Morphtron is being used extensively in all my projects and has been undergoing some significant evolution. I expect to post updates this quarter.
Morphtron is being used extensively in all my projects and has been undergoing some significant evolution. I expect to post updates this quarter.
Morphtron Components & Containers(MC2) Example - Smalltalk
o_Object new.
o getComponents an OrderedCollection()
o getComponentsNamed: ‘boo’ an OrderedCollection()o componentName ‘an Object’
o componentName: ‘hello’
o componentName ‘hello’oc_Object newNamed: ‘world’.
o addComponent: oc.
o getComponents an OrderedCollection(an Object)
oc container componentName ‘hello’
oc fullName ‘/hello/world’props_Dictionary new.
props at: #mySpecialTrait put: ‘is flexibility - hooray Morphtrons!’
op_Object newNamed: ‘h2′ withProperties: props.
op fetchProperty: #mySpecialTrait ‘is flexibility - hooray Morphtrons!’op_Object newNamed: ‘h2′ withProperties: {#mySpecialTrait. ‘is flexibility - hooray Morphtrons!’}
op fetchProperty: #mySpecialTrait
The latest version which includes Morphtron Component & Container support is 0.91.7. You can download it in the Squeak directory. Soon updates will be in changeset and/or Monticello packages.
Javascript MOPA Implementations
The following two examples use the same Javascript 1.5 based MOPA.js,
so the only differences in them have to do with output. I know that earlier versions of Morphtron ran in Javascript OSA and Web Crossing but I haven’t tested this particular file with them - so many platforms, so little time.
Navigating Distributed Object Spaces
Back in 2000, I got a chance to demo an environment based on the Morphtron derived FreeDOM architecture at Squeakend 2000. John McIntosh really captured the key ideas. One was
The thought is that the web will become a distributed object oriented space. Then the question is how to interact with it, and how to navigate and how it’s displayed. Squeak gives wonderful control over that, we must exploit that.
Squeakend 2000
At that time the outliner was often in the spotlight and the code base was not as flexible or modular as it is today. Here’s a screenshot from that era:
There’s been a lot of evolution since then - the outliner has taken its place in a larger 3D world but the core concepts have remained the same.
Download The Squeak Implementation!
Squeak 3.8 based image and changes files are available in a zip file. I’m still wrangling about what formats support - there’s no simple answer right now. It may end up both change sets and Monticello packages in Subversion which will be the common repository for other language implementations. Spoon can’t arrive too soon!
Implementing The Core MOPA Methods Part 1
A full implementation of Morphtron provides a common, transparent means of providing access to properties by using the native property if it exists. In cases where no native property exists, MOPA methods then use or optionally create an accessory. For example consider this Smalltalk(Squeak and Dolphin) implementation of fetchProperty:
fetchProperty: aSymbol
| property |
property _ self fetchNativeProperty: aSymbol.
property
ifNotNil: [^ property].
^ self fetchAccessory: aSymbol
The details of fetchNativeProperty are left up to the implementor. She can determine what access to native properties will be allowed. The following Smalltalk implementation this:
fetchNativeProperty: aSymbol
| ivarValue |
(self class allInstVarNames includes: aSymbol)
ifTrue: [”aSymbol is an ivar”
(self isPrivateInstVar: aSymbol)
ifFalse: [”aSymbol has not been declared private”
(self class lookupSelector: aSymbol) isNil
ifTrue: [self allowInstanceVariablePropertiesWithoutAccessors
ifTrue: [ivarValue _ Compiler
evaluate: ‘^’ , aSymbol asString
for: self
logged: false]]
ifFalse: [ivarValue _ self perform: aSymbol]]].
^ ivarValue
Now for a prototype-based language such as Javascript, things are simplified because all properties are native:
function fetchProperty(aName) {
/*
Using fetchProperty for accessing properties has a number of different benefits. It is easier for beginner-to-intermediate programmers and allows Morphtron behaviors to be ported between different object environments. It also lets accessories be used transparently as properties. That said, a programmer with sufficient knowledge can still use built-in properties and accessories however she wants. See also fetchAccessory. One interesting use of accessories is for undo.
*/
var theProperty=this[aName];
if(typeof(theProperty)==’undefined’) {
theProperty=this.fetchAccessory(aName);
}
return(theProperty);
}