| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
Senior Member
Join Date: Aug 2008
Posts: 102
|
I was wondering what everyone's preference is in flash, I use AS3 and since I'm just making small apps and games I mainly use Composition, but I was wondering how many of you use inheritance.
I can see using inheritance if your doing a larger project where architecture is important, but I'm not doing those at the moment. Thoughts and opinions very welcome, I'd like to hear others thoughts and preferences |
|
|
|
|
|
#2 |
|
Pipty rupees only!
Join Date: Jul 2007
Location: Novosibirsk, Russia
Posts: 1,713
|
I almost always use inheritance, though this way is not a panacea for any problem. This is just a way I got used to. And I think it requres less coding.
But sometimes it's realy neccessary to use composition. For example you create a class which is generally inherited from another class. But some of its methods are a little bit another. Their difference cannot be programmed overridingly. Sometimes for example methods have just another return types - you cannot just override them. So composition with both implementing some new interface will be the best solution. Actualy any class relationship, I think, has its own right to exist and has its own place to be used. It realy depends on a sitation. I think using only this, or only that is a bad practice either... That's just what I think, and how I see things. This opinion helps me... for a while
__________________
fly high |
|
|
|
|
|
|
|
|
#3 |
|
member
|
On the whole, composition is a better practice to follow, because:
Inheritance = compile-time. Composition = run-time. That said, it is a massive subject and completely depends on your project, code library and requirements - and probably 50 other things too. Regards, snapple |
|
|
|
|
|
#4 |
|
Obfuscated Coder
Join Date: Apr 2008
Posts: 697
|
It really depends on what you're trying to do. Some solutions lend themselves to inheritance, and others to composition. In reality though, you'll find that both are useful in conjunction with each other.
You might want to use composition if you are trying to extend or improve Flash's bizarre collection of Sound related classes, as they are disparate and truly need to be corralled together if they are to be used meaningfully. Done correctly, this in turn can lead you to use your improved sound player in other composites with relative ease and without a great deal of pain and suffering. On the other hand, inheritance is a great way to extend the functionality of standard buttons and movieclips by altering default functions to provide template hooks or to tell movieclip subclasses that they should dispatch events in new and interesting situations.
__________________
man.mask = mask_mc; Sigh. The AS3 version just doesn't look at nice as 'man.setMask(mask_mc);' Last edited by maskedMan; 11-25-2008 at 06:37 PM.. |
|
|
|
|
|
#5 | |
|
Member
Join Date: Aug 2007
Location: Ascot, UK
Posts: 67
|
The Gang of Four recommended composition over inheritance in most things.
But one of their own exceptions worth noting (and stated explicitly by them) is that of the Template Method pattern, where the entire pattern relies on the concept of inheritance. In general, though: Quote:
EDIT: Just to add, If you want to have some regard for those who are going to be maintaining your code (if that won't be you) then you should probably respect the principles of encapsulation.
__________________
www.visualharmonics.co.uk Last edited by NickZA; 12-16-2008 at 08:59 AM.. |
|
|
|
|
|
|
#7 |
|
Guest
Posts: n/a
|
In simple words inheritance manes to inherit some properties from other,
|
|
|
|
#8 |
|
jordanrift.com
Join Date: Sep 2007
Location: Phoenix, AZ
Posts: 297
|
I tend to try not to get too hung up on one vs the other. I use them both *where it makes sense to use them*. I tend to favor composition where I can, as it leads to looser coupling and fewer dependencies. But either, used properly, will get the job done.
|
|
|
|
|
|
#9 |
|
Obfuscated Coder
Join Date: Apr 2008
Posts: 697
|
Nice to revisit this topic after so long.
As time has progressed, I have found myself doing one thing less often and that is assigning a Class or a Base Class to a library instance. Since I have so little control over the library at my job, trying to assign linkages to the library symbols is extremely counter-productive because I can't predict what will change. Therefore, I have ceased using inheritance to extend movieclips and instead use composition by creating decorators and wrappers for those movieclips. Working by myself, I had no issues with extending movieclip since I always knew how things would be structured but now I find that I only ever give a library item a class name when I know I have to instantiate it at runtime. Even though it's mostly due to external factors (ie: other team members), I chalk another one up for composition.
__________________
man.mask = mask_mc; Sigh. The AS3 version just doesn't look at nice as 'man.setMask(mask_mc);' |
|
|
|
|
|
#10 |
|
Tech Strat
|
I use more of inheritance and comparitively less of composition. In the end it is all decided on what kind of project you are working on!
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| mxml inheritance | Elephantium | Flex 2 & 3 | 2 | 04-23-2008 08:24 PM |
| Delegation, Aggregation, and Composition....oh my! | Flash Gordon | ActionScript 3.0 | 14 | 03-26-2008 04:18 AM |
| Classes and inheritance | kdawg | ActionScript 3.0 | 5 | 09-04-2007 09:46 PM |
| Controlling object timeline w/ composition | diogobaeder | ActionScript 2.0 | 0 | 04-21-2007 03:56 AM |
| OOP Theory: Composition vs. Inheritance | LostInRecursion | ActionScript 2.0 | 2 | 12-29-2005 02:17 AM |