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!
_______________________________________________
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