The Power of the Composite Pattern
In my first post on MC2, I said Morphtrons have
the ability to act as components and/or containers
But this deserves more attention as the Composite pattern it represents is one of the most important and pervasive patterns in practice because things in the “real” world are always contained and often contain other things. Back in the mid-1980’s the integrated software environment, Framework, written by Xerox PARC alum Robert Carr demonstrated to me that there were significant benefits to orgainizing everything into a hierarchy of objects. Carr won a Profile In Technical Excellence award in 1985 for Framework. One of the benefits of the Framework approach was that there was no notion of “applications” and the degree of interoperability was astounding and still some 20 years later unsurpassed in a number of respects. MC2 brings back the kind of easy interoperability seen in Framework but missing in Smalltalk. Sure if you are a knowledgeable Smalltalker, you can integrate any two solutions but each one tends to be a special case. Often you end up having to gain a deep understanding of an object just to do something relatively simple with it. In some cases you end up having to analyze whether to refactor the class or create a subclass. With Morphtron you can take existing objects and use them together quickly and easily. As a simple example take two tools that come with Squeak the MPEG movie player and Sound Recorder. Suppose you want objects that have movie players which have their own sound recorders:
myMediaRoom:=Object newNamed: ‘myMediaRoom’.
m_(MPEGMoviePlayerMorph newNamed: ‘Movie Player’) openInWorld.
myMediaRoom addComponent: m.
s:=( RecordingControlsMorph newNamed: ‘Sound Recorder’) openInWorld
m addComponent: s.m fullName ‘/myMediaRoom/Movie Player’
s fullName ‘/myMediaRoom/Movie Player/Sound Recorder’
No refactoring, no new subclasses, just the capabilities you wanted to create from two classes you didn’t author.