Re: [Flashcoders] how to call method in sub-class instace?

2007-06-30 Thread Amir T Rocker

Hi stranger ,  :)

I dont think I quite understand what you need, however i will try anyway.
[quote] "How do you get a super-class instance to call an over-riding 
method in a sub-class"


Inheritance assumes that you use a 'general' base class and a 
'specialized' subclass. To make sure I understand you right : You 
need to call a method on a child class from inside the Parent class, 
right ? Does it matter from where you call the method ? As long as 
you have a reference to the subclass instance - call the method directly.


class MySuperClass extends Object {
.. important general code here 
}
class ChildClass extends MySuperClass {
... important specialized code here 
}

var msc:Class = new MySuperClass();

var childRef:ChildClass = msc.getChildClassFromList() as ChildClass; 
( I assume the class was stored inside an Array(List)  )
childRef.doDesiredAction( 'execute some really important childClass 
code' ); // there you go :)


[quote] "Furthermore, any input values not caught by the parsers of 
the sub-classes need to get passed back up to the super-class."

Calling a method of the Superclass is easy. Just use 'super'.


var msc:Class = new MySuperClass();
var childRef:ChildClass = msc.getChildClassFromList() as ChildClass; 
( I assume the class was stored inside an Array(List)  )


class MySuperClass extends Object {
.. important general code here 

public function doDesiredAction( arg:String){
super.doGeneralDataProcessing( arg );
}

}

class ChildClass extends MySuperClass {
... important specialized code here 

public function doDesiredAction( arg:String){
super.doGeneralDataProcessing( arg );
}
}

childRef.doDesiredAction( 'calls the super class' ); // there you go :)

[quote] "Does this make sense?"
No offense , but no !!! First as a general rule of thumb: 'Favor 
Composition over Inheritance' [Sierra|Bates] - Inheritance ties you 
down. Say you implement the system as you described
and in 3 months you need to change the BaseClass - suddenly all your 
subclasses, needing to call the base class for processing, must be 
changed since they all depend on your
base class -> Strategy Pattern is recommended over inheritance ( but 
thats just my opinion )

Command Pattern to execute the different Parser Classes.
It seems to me that your classes have high coupling / low Cohesion - 
meaning that you use several classes to get one job done , it may 
seem like a good idea at first ,
using the specialized class A, the base class B, another specialized 
class C and so on to work together and parse the desired data.
However it is advised that each class takes care of One 
Responsibility. I dont want to be pretentious, so if you already know 
all that , please forgive :)
So I assume you have written one parser for each special file format 
- a .xml parser  , a .txt parser, a loadVars parser and so on.
They all extend MySuperParser. So why splitting responsibility of 
parsing data across base and child classes ?
Has the BaseClass features / responsibilities that all subclasses 
need ? if so - fine, just call the base class methods from inside your

specialized subClass Parser BEFORE you do the specialized processing like so :

public function mySubClassSpecializedParsingMethod( specialParam:* ) :void {
super.BaseClassPrepFirst( specialParam );
var preppedData:* = super.getPreppedData(); // I havent 
really tried this line :) see wether it works

this.doSpecializedPrepping( preppedData );
}

If you want to freshen up on Composition over Inheritance - This Book 
is my all time favoured Design Pattern and Bets Practice Programming 
Book !!
HEAD FIRST - DESIGN PATTERNS ( Elisabeth Freeman & Eric Freeman || 
Kathy Sierra || Bert Bates )
This was the best Book about Design Pattern - actually generally 
about good Programming.


I hope I was able to help you a bit - did I get it right ? I hope :)

Best of luck
Amir

P.S.
Lingo is NOT OOP -> dont get me wrong ! lingo rocks!!! but its 
nothing like ActionScript or Java -> Even the Javascript DOM for 
Lingo is strange to say the least :)

But again - lingo rocks!!




Am 11:32 PM 6/29/2007 schrieben Sie:
How do you get a super-class instance to call an over-riding method 
in a sub-class?  I'm using AS2.


I'm parsing data into an object.  The parser method is generalized, 
so it should be in the super-class, I think...  But there are 
exceptions in the sub-classes.  The call to start loading the data 
begins in the super-class, but some of the sub-classes might have 
there own over-riding parser methods.  Furthermore, any input values 
not caught by the parsers of the sub-classes need to get passed back 
up to the super-class.


Does this make sense?  I did this kind of thing all the time with 
lingo, but since I've been reading Moock I'm trying to write better 
OOP.  This has got to be a pretty common thing to run across.


Thanks!

Re: [Flashcoders] how to call method in sub-class instace?

2007-06-29 Thread Andrew Sinning
I had a typo in the name of the overriding method in the sub-class!  
Once I figured that out it worked exactly as explained in by Moock..


Thanks.

T. Michael Keesey wrote:


On 6/29/07, Andrew Sinning <[EMAIL PROTECTED]> wrote:


How do you get a super-class instance to call an over-riding method in a
sub-class?  I'm using AS2.



Just call the method. That's it.

I recall it being more complicated in Lingo, but in pretty much every
other OOP language (Java, C++, AS, etc.), when a method is called, it
uses the method of the object's class, not the method of whatever
class the calling method was defined in. (If that makes sense.)


___
[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


Re: [Flashcoders] how to call method in sub-class instace?

2007-06-29 Thread Mark Winterhalder

On 6/29/07, Andrew Sinning <[EMAIL PROTECTED]> wrote:

How do you get a super-class instance to call an over-riding method in a
sub-class?  I'm using AS2.


Hackish, but you could do SubClass.prototype.myMethod.call( this,
arg1, arg2...);

Anyway, you don't need this, because I think what you're trying to
achieve is happening automatically already.

Say you have Foo extends Bar. Bar has the 'load' method. Both have a
'parse' method, where Bar's does some general stuff and Foo's some
special, additional stuff:

class Bar {
  ...
  public function load () : Void {
 ...
  }
  public function parse ( data : XML ) : Void {
 ...
  }
}

class Foo extends Bar {
  ...
  public function parse ( data : XML ) : Void {
 super.parse( data );
 ...
  }
}

So, you do 'var foo = new Foo()', and then 'foo.load()', I think this
is what you mean by "The call to start loading the data begins in the
super-class". You wrote it in the super class, but note that it's all
happening in the scope of 'foo', an instance of Foo. There isn't
really a difference between what is in the super class and what is in
the main class -- as long as it's not overridden, it's as if the sub
class would have the exact same code (with the exception of static
properties).
When 'parse' is called on 'foo', it will be Foo's 'parse', no matter
if the piece of code is written in your Foo, Bar, or any other
ancestor class. This is all being done automatically, there is nothing
you have to do for that to happen.

However, calling the super class' method even though it's overridden
is something you have to do explicitly. This is done by prefixing
'super', like in the example above, in Foo's 'parse' method.

There are a few on the FlashNewbies list who are also just getting
into OOP with AS2. You might want to join that list, also on
ChattyFig. They'll be running into the same problems, and questions
get answered in more detail there.

HTH,
Mark





I'm parsing data into an object.  The parser method is generalized, so
it should be in the super-class, I think...  But there are exceptions in
the sub-classes.  The call to start loading the data begins in the
super-class, but some of the sub-classes might have there own
over-riding parser methods.  Furthermore, any input values not caught by
the parsers of the sub-classes need to get passed back up to the
super-class.

Does this make sense?  I did this kind of thing all the time with lingo,
but since I've been reading Moock I'm trying to write better OOP.  This
has got to be a pretty common thing to run across.

Thanks!
___
[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


Re: [Flashcoders] how to call method in sub-class instace?

2007-06-29 Thread T. Michael Keesey

On 6/29/07, Andrew Sinning <[EMAIL PROTECTED]> wrote:

How do you get a super-class instance to call an over-riding method in a
sub-class?  I'm using AS2.


Just call the method. That's it.

I recall it being more complicated in Lingo, but in pretty much every
other OOP language (Java, C++, AS, etc.), when a method is called, it
uses the method of the object's class, not the method of whatever
class the calling method was defined in. (If that makes sense.)

--
Mike Keesey
___
[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


[Flashcoders] how to call method in sub-class instace?

2007-06-29 Thread Andrew Sinning
How do you get a super-class instance to call an over-riding method in a 
sub-class?  I'm using AS2.


I'm parsing data into an object.  The parser method is generalized, so 
it should be in the super-class, I think...  But there are exceptions in 
the sub-classes.  The call to start loading the data begins in the 
super-class, but some of the sub-classes might have there own 
over-riding parser methods.  Furthermore, any input values not caught by 
the parsers of the sub-classes need to get passed back up to the 
super-class.


Does this make sense?  I did this kind of thing all the time with lingo, 
but since I've been reading Moock I'm trying to write better OOP.  This 
has got to be a pretty common thing to run across.


Thanks!
___
[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