View Full Version : OOP Question
miss_satsuma
01-13-2009, 05:49 PM
Hello everyone,
I'm starting to create a flash gallery that uses xml.
I want to make it as object oriented as possible, but i'm having a hard time determining what feature should be it's own class and what feature should be a method within the class.
The gallery is going to be a lot like the flickr gallery. I know that i can make a separate xml class that takes care of all the xml related functions.
However, will I just have one other class, Gallery.as or should my gallery be composed of different classes.
For example, should the part that handles the thumbnails be a separate Thumbnails.as class or should it simply be a method within the Gallery.as class?
Thanks a lot,
S
In OOP too you can be creative and come up with ideas about how to implement things. I would certainly not recommend an unique and huge class with everything in it. I would probably try to think about reusability, for example a thumbnail class sounds good since I might reuse it on other application. I might stick in it the loading functionality or not depending on what I want to do after. I might write a class to handle all the event for the gallery. So basically I would separate in classes as much as possible functionalities so I can reuse them in other projects.
maskedMan
01-13-2009, 06:33 PM
A good thing to strive for is for every class to have only one responsibility. In addition to the aforementioned benefits of reusability, this also means that any one class will have very few potential points of failure. The more responsibilities a class has, the more points of failure you introduce.
Not entirely coincidentally, the more responsibilities one class has, the more likely it will have to be changed at a later time, and change is an absolute hornet's nest of potential failure.
miss_satsuma
01-13-2009, 06:36 PM
Thanks ASWC for your quick reply! I really appreciate it.
So, in terms of creating a Flash photo gallery, how should i be thinking when planning my development? Should I be thinking about all the different features on the gallery: for example, scrolling thumbails, the main image area, captions, automated slideshow, errorhandling, xml loading...should all of these which i mentioned be their own separate classes? Am I on the right track in terms of how I'm thinking in my plan to create classes?
Once again, thanks so much! I reallly need someone to tell me whether or not I'm on the right track. OOP is very new to me :)
S
miss_satsuma
01-13-2009, 06:43 PM
Thanks maskedMan for your reply. I am starting to better understand how I should be structuring my classes :) Do you think i'm on the right track in terms of what i mentioned: scrolling thumbails, the main image area, captions, automated slideshow, errorhandling, xml loading...should these all be their own separate classes?
Just some thoughts...
Think in terms of breaking the problem down into chunks you can test. So you might have a class for loading the XML and one for Parsing it. So make a rough sketch of the parts you need and then work out how to implement each part of them so you can test them separately, and build them, most good code is restructured, it is rare that the first attempt will be your best. Don't implement features your not sure you really need and if possible keep the parts generic so you can reuse them, but don't go obsessive with design patterns and abstraction just to be ultra OOP, try to keep it simple and try to avoid repeating code where you can, but also if each repeated code section is a special case then if it seems cleaner and simpler then if need be repeat yourself. If the problem is initially to big for you to plan then break it into more than one make some assumption simplify the requirements and create a cut down version first. It is better to have a rock solid core than all the features implemented but it be really buggy. Be careful of breaking the problem down two much or overusing inheritance ideally you should have the whole program loaded in your mind when your making it, if you get too clever with OOP then that might not happen so there is always a balance.
I guess I am suggesting what might be termed as an agile approach where you test often ( and i don't mean unit testing, I mean test your assuptions and it works as you think it should ), and add functionality in stages and don't assume that you can top down design everything. In terms of specific advice there is no 'right' solution, just some that are better than others, and the solution will depend on your skill and someone elses approach may not suit you or your level.
A class or a method should be possible to describe in a sentence if you need an essay the class is too big.
A class or a method should be possible to describe in a sentence if you need an essay the class is too big.
That's a good way to put it, I'll reuse that if you don't mind! ;)
lucidmedia
01-14-2009, 01:35 AM
The question you are asking is quite a deep one... once you are feeling a bit more comfortable with OOP you may want to do some reading into design patterns. There are a variety of Design patterns, each one structuring the relationships between your classes differently based upon your needs and the needs of your users.
miss_satsuma
01-14-2009, 12:44 PM
Thanks everyone for your replies.
I think one thing i'm struggling with is when designing an app, like a Flash photo gallery, i'm having trouble distinguishing between whether a feature should be made into a class or method of a class.
For example, i want my photo gallery to have back and forward arrows so users can iterate through the various photos.
Would i turn this functionality into a class of it's own or would it be a method of my LoadImage class?
-S
grilldor
01-14-2009, 02:59 PM
Thanks everyone for your replies.
I think one thing i'm struggling with is when designing an app, like a Flash photo gallery, i'm having trouble distinguishing between whether a feature should be made into a class or method of a class.
For example, i want my photo gallery to have back and forward arrows so users can iterate through the various photos.
Would i turn this functionality into a class of it's own or would it be a method of my LoadImage class?
-S
Well, as it was said previously, its not written anywhere "how" to make this. However, one thing i would do, is not to include the buttons in the gallery class. Instead, the class would contain 2 public methods to move the pictures left or right.
The buttons and the calls to those public methods would be made in a higher class (closer to the document class)
Also, this way, you can change how your button look without having to edit one bit of the gallery class.
miss_satsuma
01-16-2009, 09:08 PM
Thanks everyone for your very helpful advice!
I have also started to read "Actionscript 3.0 Design Patterns" published by O'Reilly. So far it's great!
-S
Mazoonist
01-16-2009, 09:14 PM
It's a great book, yeah. Not the greatest editing job, though. You'll find a lot of page disconnects--pages that start off out of sync with where the last page left off. Sometimes it happens in the middle of a block of code.
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.