arrg, I'm doing to many things today..
in the construct that would be
makerImpl = new JuiceMaster();
instead of;
makerImpl = new JuiceMaker();
I'm sure you knew that but, I'm just a perfectionist even with irrelevant
emails. :)
Mike
On 9/12/07, Michael Schmalle <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> below is the 'concrete' version;
>
>
> class JuiceMaster
> {
> public function makeJuice(type:String):void
> {
> trace("Happily making", type, "juice!", "Tralalala!");
> }
> }
>
> public class JuiceMaker
> extends Button
> {
>
> private var _makerClass:Class;
> private var makerImpl:JuiceMaster;
>
> public function set makerClass(value:Class):void
> {
> _makerClass = value;
> makerImpl = new _makerClass();
> }
>
> public function set makerClass():Class
> {
> return makerImpl;
> }
>
> public function JuiceMaker()
> {
> super();
>
> // you could just make the default implementation here
> // thats about as concrete as it gets
> makerImpl = new JuiceMaker();
> }
>
> public function makeJuice(type:String):void
> {
> if (makerImpl is JuiceMaster)
> makerImpl.makeJuice(type);
> }
> }
>
>
> Notice the types are concrete meaning you are programming to an
> implemented class, no polymorphism here.
>
> And note this is not 'real' decoration either.
>
> Real decoration means you pass a reference to an instance of the decorator
> and actually call the decorators methods.
>
> This is like Composition Decorating, and maybe there is some other OO word
> for it. I don't care about the technical of it just that it IS a pattern
> good for DisplayObjects.
>
> Peace, Mike
>
> On 9/12/07, Claudia Barnal <[EMAIL PROTECTED]> wrote:
> >
> > Yeah, I had thought about something using composition. But somewhere I
> > had read that the Decorator was what I needed :(
> >
> > I'll do it as you mentioned, but I would still love to hear about the
> > Concrete class that you mention :)
> >
> > Thanks Michael!
> >
> > On 9/12/07, Michael Schmalle < [EMAIL PROTECTED]> wrote:
> >
> > > Oh yeah
> > >
> > > <JuiceMaker id="myJuiceMaker" decorator="{JuiceMaster}" click="
> > > myJuiceMaker.makeJuice('orange')" />
> > >
> > > is supposed to be;
> > >
> > > <JuiceMaker id="myJuiceMaker" makerClass="{JuiceMaster}" click="
> > > myJuiceMaker.makeJuice('orange')" />
> > >
> > >
> > > On 9/12/07, Michael Schmalle <[EMAIL PROTECTED]> wrote:
> > >
> > > > Hi,
> > > >
> > > > You can't decorate a UIComponent since it is a DisplayObject and
> > > > needs to be added to the display list.
> > > >
> > > > You have to either us composition or subclass Button and use an
> > > > interface and pass the class to decorate the Button with.
> > > >
> > > > <JuiceMaker id="myJuiceMaker" decorator="{JuiceMaster}" click="
> > > > myJuiceMaker.makeJuice('orange')" />
> > > >
> > > >
> > > > class JuiceMaster
> > > > implemented IJuiceMaker
> > > > {
> > > > public function makeJuice(type:String):void
> > > > {
> > > > trace("Happily making", type, "juice!", "Tralalala!");
> > > > }
> > > > }
> > > >
> > > > public class JuiceMaker
> > > > extends Button
> > > > implemented IJuiceMaker
> > > > {
> > > >
> > > > private var _makerClass:Class;
> > > > private var makerImpl:IJuiceMaster;
> > > >
> > > > public function set makerClass(value:Class):void
> > > > {
> > > > _makerClass = value;
> > > > makerImpl = new _makerClass();
> > > > }
> > > >
> > > > public function set makerClass():Class
> > > > {
> > > > return makerImpl;
> > > > }
> > > >
> > > > public function JuiceMaker()
> > > > {
> > > > super();
> > > > }
> > > >
> > > > public function makeJuice(type:String):void
> > > > {
> > > > if (makerImpl is IJuiceMaker)
> > > > makerImpl.makeJuice(type);
> > > > }
> > > > }
> > > >
> > > >
> > > > public interface IJuiceMaker
> > > > {
> > > > function makeJuice(type:String):void;
> > > > }
> > > >
> > > >
> > > > The above is something that would help what you are trying to
> > > > achieve with display object.
> > > >
> > > > You could also drop the interfaces and use concrete types but hey,
> > > > if your asking about decorators, your asking about design patterns. ;-)
> > > >
> > > > Peace, Mike
> > > >
> > > > On 9/12/07, Claudia Barnal < [EMAIL PROTECTED]> wrote:
> > > > >
> > > > > I believe I might be missing something with the Decorator
> > > > > Pattern.
> > > > > I've tried to get a simple example to work, but I get too mixed up
> > > > > with all the abstracts and what not.
> > > > >
> > > > > Here's what I'm trying to do:
> > > > >
> > > > > Extend a Button and add some functionality to it gotten from
> > > > > another
> > > > > class (non visual). From what I can understand, this is what the
> > > > > Decorator Pattern is for.
> > > > >
> > > > > In pseudo code this is the basic functionality I want:
> > > > >
> > > > > class JuiceMaster
> > > > > {
> > > > > public function makeJuice(type:String):void
> > > > > {
> > > > > trace("Happily making", type, "juice!", "Tralalala!");
> > > > > }
> > > > > }
> > > > >
> > > > > class JuiceMaker extends Button
> > > > > {
> > > > > public function JuiceMaker()
> > > > > {
> > > > > Super();
> > > > > makeJuice("apple");
> > > > > }
> > > > > }
> > > > >
> > > > > And in MXML, I should be able to do something like this:
> > > > >
> > > > > <JuiceMaker id="myJuiceMaker" click="myJuiceMaker.makeJuice('orange')"
> > > > > />
> > > > >
> > > > > Of course this example isn't going into any detail, and doesn't
> > > > > make
> > > > > much sense, but this is somewhat my need.
> > > > >
> > > > > Any explicit explanation on how to get something like this to work
> > > > > with the Decorator Pattern is greatly appreciated.
> > > > >
> > > > > Thanks!
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Teoti Graphix
> > > > http://www.teotigraphix.com
> > > >
> > > > Blog - Flex2Components
> > > > http://www.flex2components.com
> > > >
> > > > You can find more by solving the problem then by 'asking the
> > > > question'.
> > >
> > >
> > >
> > >
> > > --
> > > Teoti Graphix
> > > http://www.teotigraphix.com
> > >
> > > Blog - Flex2Components
> > > http://www.flex2components.com
> > >
> > > You can find more by solving the problem then by 'asking the
> > > question'.
> > >
> > >
> >
> >
>
>
>
> --
> Teoti Graphix
> http://www.teotigraphix.com
>
> Blog - Flex2Components
> http://www.flex2components.com
>
> You can find more by solving the problem then by 'asking the question'.
>
--
Teoti Graphix
http://www.teotigraphix.com
Blog - Flex2Components
http://www.flex2components.com
You can find more by solving the problem then by 'asking the question'.