« How Do You Test Your Code? | Main | The Cell Project »

That which we call a subclass, by any other name...

.. would make more sense.

ActionScript is not my first "programming language", and a lot about actionScript (and Flash in general) has confused me over the years. The whole subclass and superclass is a case in point.

It's the use of "sub" that I find distracting. "Sub" usually implies a smaller part of a bigger body. In my first programming classes, a subroutine was used to encapsulate the code of a larger routine. In most of what I've read on OOP in ActionScript, it seems almost as if "sub" is being used in a taxonomical sense, since most examples are fairly taxonomical. For example, there may be a class for "vehicle" and a subclass of "car", which extends the vehicle class. So, while car is a subset of all vehicles, is the car class really a subset of all vehicle classes?

I could be completely wrong on this, but I like to think of a superclass as a "base class" and subclass as an "expanded class".

For the sake of clarity, I've rewritten the tootsie roll example ;-)

Let's say that tootsie rolls are the base class. Add a hard candy shell and a stick, and we have an expanded class. Hmmm...I must be hungry.

Time for me to get something to eat, and think more about this later.

Comments

You just had to bring chocolate into it... Suddenly I have an urge to balance the universe and make a beer analogy. Hops is to Object as Beer is to MovieClip.

Regardless of the universal anagolous battle of the sexes via food & code, I agree. Sub is a dumb name, and counter-intuitive to learning. Extends is such a better word. Maybe that's why I dig AS2.

...heck with this, time for Cap'n Crunch.

hell yeah, i know exactly what you are saying (well except for the tootsie roll thing ;) )

The thing that solved it for me was to force myself to mentally subsititute the word "specialized" for "sub" whenever talking about classes. that seemed to let the idea really sink in.

come to think of it im not sure if that makes sinse either...i must be hungry too.

yeah, i agree extends is much clearer.

Extends doesn't seem to clearly show the dependancy though. Although I see sub as a bit problematic it does clearly identify that the sub class is dependant on the super class.

I think that that's where the term sub comes from.

please no flaming for symantics, it just makes me think of "if its not too late, please, make it a cheeeeeese burger"

cheers, doc

"'Sub' usually implies a smaller part of a bigger body." Righto. Animal is the bigger body. Dog is a sub-class of that. A smaller part of the bigger thing. It's more of a matter of thinking in terms of types of things, rather than individual things.
Everything in Flash is an Object. One part of all those things are movie clips. Of those movie clips, part are UIComponents.
Probably doesn't help, but it's the best I could do. :)

I think you are looking at this from the wrong end, I think Keiths explanation is nearest to the right way of thinking....

you said... 'think of a superclass as a "base class" and subclass as an "expanded class"'

the first bit is correct, it is 'super' class (as in very big, parent of all its subclasses)

The next bit is wrong, it is not an expansion of the class, it is infact a specialisation of the class (eg, car is a specialised version of a vehicle)

Hence a sub class represents a smaller part of the bigger superclass swarm. There are billions of vehicles in the world, millions of cars (vehicles with 4 wheels & seats), and thousands of ferraris (cars that go fast and are red). super, sub, sub etc, each more specialised and hence a smaller 'sub' group of its parent class.

Adam did a great job of explaining it. You have to think in terms of specificity. Subclasses are always more specific than their superclass, and hence resolve to a smaller group of objects.

The real trick is to look at what "sub" or "super" is being applied to. If you are applying it to a "class" then you are essentially dealing with taxonomical classification. Classes are really just a way of defining and organizing objects logically - they prevent us from defining objects freeform on demand. On the other hand, if you are applying "sub" to an object, then you ARE dealing with "a smaller part of a bigger body" - hence, a sub-object refers to an object contained within a larger aggregate object.

Heck, you can even look it up in the dictionary, and who can argue with Webster (I loved that little guy):
Subclass: "A subdivision of a set or class."

:)

cheers,
Grant.

ok, mental shift here...I think I've been really stuck in the procedural mindset.

Have I been focussing on the class itself, instead of the object that it describes?

My emotional attachment to Object is miniscule compared to my attachment to MovieClip. MovieClip, in a personal sense, is awesome. Calling it a sub-class of Object is demeaning, and insulting to my very being considering I'm a Flash Developer.

Although a Bus may be a more specialized, or "sub-category" of Vehicle, that evolution and improvement far out-shines the original class' definition. Extends, however, does have a sort of "detached" feeling to it, so I can see how the relationship, ecspecially from a programatic sense, is not implied.

It could be perception. "I like calling it sub because all the base functions are written for you in UIComponent, therefore, your ScrollBar is mereley extending what Flash already provides for you."

On the flip-side, "I like calling it extends because you have extended my UIComponent far beyond the simple digital-play-doo via your creation of a ScrollBar built upon UIComponent."

Save work vs. take it to the next level.

...I'm hungry again.

I also find both 'super' and 'sub' *very* confusing.

As you say 'sub' sounds like it refers to the smaller code, which is the base class.

On top of this, 'super' (as in 'superman') sounds like it refers to the class that can do more - the extended class, rather than the (maybe abstract and useless) base class.

How do I avoid the confusion? I think of superscript and subscript (as in a word processor). 'Super' is at the top, 'Sub' is at the bottom, so super comes first, then the sub.

OK, it may sound stupid, but it works for me and there's no other way I can remember these related correctly.

Actually, remembering 'super' and 'sub' refer to what the class represents rather than the class code would do the trick. But when I'm coding, I tend to think a class as some piece of code and can't avoid the confusion. I don't think it's related to procedural mindset.

And they are not used as nouns only. What does 'Subclassing a Windows control' mean? Does 'Specializing a Windows control' or 'Extending a Windows control' sound better? I'd prefer 'base' and 'extended' every time.

Regards,
Burak