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.
Anyhow, hope that gets the gears turning. =)
DISCLAIMER: Didn't spell check or test anything in the compiler so maybe
some typos. =)
-erik
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of David Ham
Sent: Monday, January 29, 2007 7:12 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Flair Pattern bad mixins good (?)
> Anyhow I tend not to use decorators (matter of personal taste). I
> prefer to
> not Frankenstein an object at runtime and rather use mixins
> (composition +
> interfaces).
Ah, thank you, now we are getting somewhere!
Tell me about mixins. I have used EventDispatcher before, but I am
unfamiliar with the theory behind mixins in general.
In my app, i have objects that can be dragged around in a Room, and
they have a "snapping" behavior that lets them snap to the walls of
the room, and in some cases, rotate themselves so that a given side
of the object is always to the wall.
Currently, my snapping behavior is in a separate class like the one
at the top of this thread. If the room object has snapping enabled,
the SnapFlair class adds an object with a bunch of methods and
properties to it. The snapping methods are triggered by an event that
is broadcast as the room object is being dragged.
How would I implement this as a mixin?
Many thanks fellas!
As for Steven, sounds like HE'S got a case of the Mondays! *smirk*
OK
DAH
_______________________________________________
[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
_______________________________________________
[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