Erik Bianchi wrote:
The theory of mixins originated from multiple inheritance programming
languages such as C++.

So for example: Say you wanted to make an object dragable, clickable and
resizable. You would then create separate classes called: Dragable,
Clickable and Resizable (common naming convention for a mixin).

Then your base class would just inherit form those 3 classes.

Since AS2 doesn't support multiple inheritances you can emulate a mixin
using interfaces and composed classes.

For example:

IClickable, IDragable, IResizable

So then your AS2 class would say:

Class MyClass extends Whatever implements IClickable, IDragable, IResizable

Those interfaces just specify what methods your class has to support.

From there you could have a class (or a consolidated class) implement that
functionality

private var clickable:Clickable = new Clickable();
private var dragable:Dragable = new Dragable();
private var resizeable:Resizeable = new Resizeable();

from there you just forward / wire the appropriate methods to its
corresponding instances.

public function startResize()
{
        this.resizeable.startResize();
}

Or for arguments:

public function startResize()
{
        this.resizeable.apply.(this.resizeable.startResize, arguments);
}

You could get even more fancy by externalizing those classes so based on
various rules you could pass in different resize logic, etc.


enter the State and Strategy Patterns :)

The State Pattern would be implemented like the above example when you described a fancier version with multiple resize classes. Those resize classes can be swapped out at run-time to provide different functionality. For example, the object resizes from the center or from the corner depending on the resize class composited.

The Strategy Pattern is similar but the composited functionality is an encapsulated algorithm. In theory, you would have a bunch of concrete algorithm classes and depending on your needs at run-time composite the right one to perform a calculation.

-- james


--
James O'Reilly  —  Consultant
Adobe Certified Flash Expert
http://www.jamesor.com
Design • Code • Train




_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to