« 200,000,000 Google Earth Users | Main | UNIX Commands = Startup Ideas »

March 25, 2007

Flex Class Hierarchy

I was playing around with Flex a few months ago and made this graph to figure out how the class library is structured:

Flex Class Hierarchy

The interesting bit (at least to me) is the depth of the inheritance chain from Object to the control classes. There's quite a few shallow classes for generic services (Timer, IME, Effects, Files, URLs). This is coupled with a really deep hierarchy to controls via Object > DisplayObject > InteractiveObject > DisplayObjectContainer > Sprite > FlexSprite > UIComponent

Years ago, when WPF was still called Avalon, Miguel de Icaza criticized the depth of the inheritance chain from Object to Button. At the time, it was 10 degrees of separation between the two. Flex weighs in at 8 for its Button.

Alan Kay first said Simple things should be simple. Complex things should be possible. This was one of the stated goals for WPF. As an object-oriented framework, WPF/.Net3 is a descendant of great grandaddy of GUI frameworks, Smalltalk (as is Flex). However, the Squeak class hierarchy reveals that it uses a very short inheritance chain for controls: Object > Morph > BorderedMorph > RectangleMorph > SimpleButtonMorph > ButtonMorph. This is 5 degrees of separation, but only one of them is essential to a Button's behavior: Morph. Squeak's Morph is a god class that contains the lion's share of behavior. The other base classes for ButtonMorph are lightweight, mostly adding rendering behavior.

Over the past year I've mentored several developers in WPF and .Net 3.0, which have a similar object model for UI controls. I observed a trend in how these deep hierarchies affected these developer's learning curve. On the one hand, there's the advantage of the common behavior forced on the plateau of controls that inherit at the deepest leaf nodes of the tree. Idioms learned for one control tend to generalize to other controls. On the other hand, the long, flat stretch of intermediate subclasses means that the implementation of this common behavior is widely distributed. So it takes longer to find answers to questions like: "Can I cast X to a Y here?" and "Can I add Foo as a child of Bar?".

Posted by Devon at March 25, 2007 01:10 PM

Comments

Just to note, as far as I am aware (although it does not really affect your point much) - everything up to FlexSprite is an object belonging to the Flash Player, and is available in either Flash CS3 and Flex.

The Flex framework begins with UI component.

The difference being you can view and alter the Flex framework classes as they are written in ActionScipt, this is not true of, for example, the MovieClip class, which belongs to the player.

Posted by: zz_james [TypeKey Profile Page] at October 4, 2007 06:29 AM

Post a comment

Thanks for signing in, . Now you can comment. (sign out)

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


Remember me?