Yeah, i thought of using inheritance but in this case Composition allows me
to instantiate the classes in a way that it would be easier to hand down the
items to other people and they don't have to mess with the code.

At the moment I'm only overwriting one method, and maybe I will have to
overwrite one property so that is why I didnt think it would be an overhead.


Maybe I didnt explained my items correctly but this is how it works

Main Class
-method1 (calls method2 when method 1 is finished)
-method2 (calls method3 when method 2 is finished)
-method3 (does nothing)

Copy Class
//create a wrapper of Main Class
method2 = this.method2 (overwriting?);
-method2 (calls method 3 of main when its finished, this allows me to
"overwrite" the method of main).

Does this makes sense?

Thanks!
-h

On 6/8/07, David Ngo <[EMAIL PROTECTED]> wrote:

No. You would have to create wrappers for all three methods. It sounds
like
you should be using Inheritance instead of Composition if you're
overriding
that many methods...



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Helmut
Granda
Sent: Friday, June 08, 2007 12:40 PM
To: flashcoders@chattyfig.figleaf.com
Subject: Re: [Flashcoders] Composition access

One more question while in Composition mode

lets say I have my main class

Main
-method1 (calls method2)
-method2 (calls method3)
-method3

With Inheritance I could do

Copy

-method2 (calls method3 of Main)

When instantiating Copy it would know to use method1, and method3 from
original while using method2 from the copy.

Is there a way to achieve the same issue with composition?

So far thanks to the explanation above I can access the methods of Main
from
a Copy instantiation but cant access methods of Copy from Main when
needed.
I might be approaching this all wrong which might be the main issue :(

TIA

On 6/8/07, Helmut Granda <[EMAIL PROTECTED]> wrote:
>
> hey David,
>
> your suggestion works perfectly, it was my implementation that was
> breaking the code.
>
> Thanks again.
> -h
>
> On 6/8/07, Helmut Granda <[EMAIL PROTECTED]> wrote:
> >
> > Thanks David,
> >
> > For some odd reason if I do in my coopy
> >
> > public function init():Void
> > {
> > trace("init in copy class");
> > }
> >
> > it wont fire but it will fire the init method from the Original Class
> > (which by the way seem very similar to inheritance :) ).... any ideas
why
> > this could be happening?
> >
> > Thanks again...
> >
> > On 6/8/07, David Ngo < [EMAIL PROTECTED]> wrote:
> > >
> > > You'd basically create a 'wrapper' method:
> > >
> > > class CopyClass {
> > >
> > >         private var original:OriginalClass;
> > >         private var mc:MovieClip;
> > >
> > >         public function CopyClass(mc:MovieClip)
> > >         {
> > >                 this.mc = mc;
> > >                 original = new OriginalClass(mc);
> > >         }
> > >
> > >         public function init():Void
> > >         {
> > >                 original.init ();
> > >         }
> > > }
> > >
> > >
> > > It's almost like calling super. However, if you're looking to
override
> > > the
> > > original class' init(), then you don't need to call original.init()
> > > and just
> > > create your logic in your CopyClass' init method. This is the one
> > > drawback
> > > to using Composition over Inheritance, but I would say it's worth it
> > > in the
> > > long-run.
> > >
> > >
> > > David
> > >
> > >
> > > -----Original Message-----
> > > From: [EMAIL PROTECTED]
> > > [mailto:[EMAIL PROTECTED] On Behalf Of
Helmut
> > > Granda
> > > Sent: Friday, June 08, 2007 10:27 AM
> > > To: Flashcoders mailing list
> > > Subject: [Flashcoders] Composition access
> > >
> > > I am slowly moving from inheritance to composition for a specific
> > > project,
> > > one way to "extend" my classes is by creating a copy of them into
the
> > > new
> > > created classes...
> > >
> > > class OriginalClass {
> > >
> > > var mc:MovieClip;
> > >
> > > function original(mc:MovieClip) {
> > >   this.mc = mc;
> > >   init();
> > > };
> > >
> > > function init() {
> > >   trace("original");
> > > }
> > >
> > > ------ now trying to overwrite init
> > >
> > > class CopyClass {
> > >
> > > var original : OriginalClass;
> > > var mc : MovieClip;
> > >
> > > function CopyClass(mc:MovieClip) {
> > > this.mc = mc;
> > > original = new OriginalClass(mc);
> > >
> > > }
> > >
> > > //How do I access init from the original class? I know that doing
> > > inheritance I can just declare a new init method in my CopyClass but
> > > in this
> > > case it doesnt work that way.
> > >
> > > TIA
> > > _______________________________________________
> > > Flashcoders@chattyfig.figleaf.com
> > > 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
> > >
> > > _______________________________________________
> > > Flashcoders@chattyfig.figleaf.com
> > > 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
> > >
> >
> >
>
_______________________________________________
Flashcoders@chattyfig.figleaf.com
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

_______________________________________________
Flashcoders@chattyfig.figleaf.com
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

_______________________________________________
Flashcoders@chattyfig.figleaf.com
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