View Full Version : var x:Superclass = new Subclass(); ... appropriate?
drexle
09-26-2007, 07:02 AM
I'm curious if it's appropriate to do something like in the subject header:
var x:Superclass = new Subclass();
Flash Gordon
09-26-2007, 07:06 AM
yes, in fact it is one of the key principles of OO: Program to the interface and not the implementation.
drexle
09-26-2007, 07:33 AM
Awesome!
I'm following the crowd and reading over the Head First Design Patterns book and I'm playing around with the examples in the first chapter. I wanted to make characters who could equip "equipment" objects regardless of what subclass of equipment it might be (hacksaw subclass, pastry subclass, tophat subclass, etc). I just wanted to make sure I was interpreting things correctly.
Flash Gordon
09-26-2007, 07:35 AM
yup, of all the things I've learned that....there is a reason while that is the first rule. It is essential to polymorphism.
good luck with your reading. I read the head first book, but I don't remeber the examples you are giving....
vBulletin® v3.7.1, Copyright ©2000-2008, Jelsoft Enterprises Ltd.