MOPA


Implementation and Javascript and Javascript OSA and MOPA and MPF and Mozilla and Web Crossing and Yahoo Widgets(Konfabulator)28 Jul 2006 04:15 am

The following two examples use the same Javascript 1.5 based MOPA.js,

  • Browser based
  • Yahoo Widget Engine(put the MOPA.js file from above into the .kon file)

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.

MOPA and MPF and Smalltalk and Squeak27 Jul 2006 09:50 am

This simple example included in the beta image is shown below with comments and italicized results.

create a new object
o_Object new. an Object

see if it has a ‘hello world’ property
o fetchProperty: ‘hello world’. nil
put something into the hello world property
o putIntoProperty: {’hello world’. ‘first program’}

fetch the new property
o fetchProperty: ‘hello world’. ‘first program’

when you fetch all of an object’s properties, you get all the methods and instance variables along with the accessories
o fetchProperties a Dictionary(size 453)

this simple object has only one accessory
o fetchAccessories a Dictionary(’hello world’->’first program’ )
o fetchAccessory: ‘hello world’ ‘first program’

There are methods such as hasProperty and hasAccessory and other variants(hasNativeExecutableProperty) that allow you to determine what the properties an object has are.

Dolphin and Implementation and Javascript and MOPA and MPF and Mozilla and Smalltalk and Squeak and Yahoo Widgets(Konfabulator)25 Jul 2006 11:13 pm

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);

}

MOPA and MPF25 Jul 2006 09:45 pm

MOPA provides two capabilities:

  • a uniform, largely syntax neutral means of interfacing with an object’s native properties/fields/instance variables/methods.
  • a uniform, largely syntax neutral means of interfacing with properties unique to a particular instance.These unique instance properties are referred to as accessories.

The “largely syntax neutral” disclaimer is made because Morphtrons could be difficult or even impossible to fully implement in every dynamic OO language. These two capabilites make it possible to write code which can be directly executed by multiple languages across multiple platforms.

There are two executable properties which form the kernel of a Morphtron implementation.

  • fetchProperty
  • putIntoProperty


Continue Reading »

MC2 and MOIST and MOPA and MPF25 Jul 2006 08:39 am

To facilitate implementation and extension, the Morphtron architecture has been modularized into the Morphtron Programming Framework(MPF). The MPF nucleus is known as the Morphtron Object Properties and Accessories(MOPA). A Morphtron object is a collection of named properties. There are two categories of Morphtron properties - Executable and Value, each having two sub-categories Native(as determined by the host language - typically by the class) and Accessory(unique to an instance). MOPA provides the means to create, store and retrieve an object’s properties. Surrounding the Morphtron nucleus is Morphtron Components and Containers(MC2) module which provides objects with the ability to exist in hierarchical relationship to other objects. Another module is called Morphtron Observation Interchange Storage & Transport(MOIST). This is actually a collection of four interrelated sub-modules whose names reflect their function. Each of these modules will be covered in more detail later.