tag:blogger.com,1999:blog-3717133688018454834.post8979800612886095948..comments2024-01-05T11:00:14.227+00:00Comments on Iain Lobb: Do you extend or compose Sprite, MovieClip and DisplayObject?Unknownnoreply@blogger.comBlogger12125tag:blogger.com,1999:blog-3717133688018454834.post-21701539820146751132009-11-27T14:05:24.382+00:002009-11-27T14:05:24.382+00:00Hmmm, it's all very interesting. I must admit ...Hmmm, it's all very interesting. I must admit I use inheritance at 99% and I am happy with this, sub classes are quite clean that way, I don't need to reference all the methods that I need to use.<br /><br />I feel that I somehow must be missing the good sides of composition, or do something wrong, is there any good blog post about inheritance?<br /><br />Cheers,<br />TOg2thttps://www.blogger.com/profile/04410544331962002380noreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-28588506684041967712009-06-14T11:05:44.030+01:002009-06-14T11:05:44.030+01:00We can go back and forth but really this will boil...We can go back and forth but really this will boil down to a matter that simply depends on the case. Where does the class fit conceptually, with AS3s "framework" or the one you make specific to your needs and tastes? If you are extending the movieclip or sprite -merely- because it will be a visible object, then that's not very OOP, and probably what adobe had in mind when they decided to implement interfaces - their way of adhering to polymorphism (another buzz word we should all be learning). On the flip-side, just because we all "accidentally always" used inheritance till we knew better, doesn't mean there's not a time and place for it.Will Shttp://nucleusd.blogspot.comnoreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-34059144608738268122009-05-20T12:42:00.379+01:002009-05-20T12:42:00.379+01:00Since you ask for opinion, here is mine :). I favo...Since you ask for opinion, here is mine :). I favor composition, why ? Because it's cleaner and (for me anyway) it force me to think about how I design my classes and not to hack something up for quick fix. For example, a plane class doesn't need most of the Sprite/Bitmap/MovieClip method and properties on it, they are 'high level' classes, they doesn't supposed to expose those stuff. And the because you are not allowed to access things that is used to be in the Sprite/MC/Bitmap class, you ough to think about what your class are doing with it (Sprite/MC/Bitmap) and it prevent you from doing a hack because you don't have direct access to Sprite/MC/Bitmap anymore :)aaulianoreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-17063937390841823282009-05-11T19:13:00.000+01:002009-05-11T19:13:00.000+01:00As the OOP mantra goes: "Favour composition over i...As the OOP mantra goes: "Favour composition over inheritance". <br /><br />With regards to the display list, when I started doing AS3 I found I was using inheritance far too much. <br />Over the last year I've found that composition seems to work much better. Why? It's tricky to precisely define, it just seems more logical and cleaner. <br />Bet that doesn't help at all :)yezzerhttps://www.blogger.com/profile/04675712536498569142noreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-17986623433646005342009-05-06T22:56:00.000+01:002009-05-06T22:56:00.000+01:00I usually extend a Sprite or MovieClip in my class...I usually extend a Sprite or MovieClip in my classes when the instance will be on a display list. If not, I think it's better compose your class with a Sprite.<br /><br />However, you have to keep in mind that compose instead of extend use more memory and is one more step when you need to acess some property or method of the Sprite. It's a small step, but it's one more thing to slow down your app.Andre Anayahttp://blog.andreanaya.comnoreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-50294597537796712782009-05-06T16:12:00.000+01:002009-05-06T16:12:00.000+01:00Thanks guys, thanks for completely contradictory a...Thanks guys, thanks for completely contradictory answers! What do I do now!? One thing I like about composition of MovieClips is not having a million things on the autocompletion menu. I like the writing less code of extending though. Hmmm.Iainhttp://blog.iainlobb.comnoreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-81947297905899465952009-05-06T13:47:00.000+01:002009-05-06T13:47:00.000+01:00I think we need to take this outside to the car pa...I think we need to take this outside to the car park mate ;)<br /><br />I'm not sure why you'd need a load of getter / setters. Maybe on the controller classes ( Such as a BaddieHandler class that loops through all them bad boys and handles triggering them and houseKeeping ) but when you're in those child classes, the player bullets, the particles, they're kinda self supportive.<br />For the most part they need an init(), mainloop() and houseKeeping() and that's it.<br /><br />It is all kinda moot though, I think it boils down to personal preference.<br />It's like the first Bond you saw usually ends up being your favourite, even if it was Roger Moore.Squizehttp://www.gamingyourway.comnoreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-52384549376451215052009-05-06T07:11:00.000+01:002009-05-06T07:11:00.000+01:00I got to go against Squize and Felix on this one.....I got to go against Squize and Felix on this one... thems fightin words! ;)<br /><br />I use a mix, but a majority of my classes extend Sprite or MovieClip. MovieClip if its art brought in from an Assets.swf and Flash IDE. Sprite if I am dynamically creating it. <br /><br />I find it easier to not have to re-invent the wheel by creating getter/setter functions for everything. If I want to restrict or customize anything specific then I will override that function.<br /><br />So basically I combine my controller class with my view in most cases and only use the basic class/object for my data and util classes. <br /><br />Right or wrong... that is what I do. Thanks for the discussion Iain.Ickydimehttps://www.blogger.com/profile/09441385865959854926noreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-45256940491532789812009-05-05T22:57:00.000+01:002009-05-05T22:57:00.000+01:00thanks for your input felix and squize! that's 2 v...thanks for your input felix and squize! that's 2 votes for composition so far. Looks like this one's not going my way ;)<br /><br />@felix - need to correct you on that thing about classes extending MovieClip being dynamic - not true, unless you explicitly use the dynamic tag. So actually if you compose a MovieClip you've have more dynamic objects in your code.Iainhttp://blog.iainlobb.comnoreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-6138293605418934612009-05-05T22:51:00.000+01:002009-05-05T22:51:00.000+01:00I always use composition when possible. This way y...I always use composition when possible. This way you can separate the 'business logic' of the class from the MovieClip's properties. Also extending MovieClip means your classes are dynamic which is not usually good.<br /><br />On a related note I try not to use the Library Symbol Properties to link a symbol to a class. IMO it's cleaner to keep the linkage ids in the AS file.felixhttp://www.airtightinteractive.comnoreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-69602352074994290322009-05-05T22:40:00.000+01:002009-05-05T22:40:00.000+01:00I use composition, purely 'cause in my head it fee...I use composition, purely 'cause in my head it feels cluttered extending a sprite / mc, in that my class will inherit a lot of things it won't use.<br /><br />Also it feels like I'm more in control that way, that the display object is part of a whole, rather than being the whole/<br /><br />Wow, what a great post :S Sorry, tired and the words just aren't coming tonight.Squizehttp://www.gamingyourway.comnoreply@blogger.comtag:blogger.com,1999:blog-3717133688018454834.post-64041841171559280832009-05-05T22:29:00.000+01:002009-05-05T22:29:00.000+01:00I just came across this - worth a read on the topi...I just came across this - worth a read on the topic...<br /><br />http://www.moock.org/blog/archives/000248.htmlIainhttp://blog.iainlobb.comnoreply@blogger.com