Newbie: Calling an overriden method from a child class...
-
I hope that sounds right? I will explain... I have built a class (lets call it 'X') that constructs a StringBuilder and then passes it back. All is OK except within this class it calls a number of methods from a base class higher up. Here comes the tricky bit. Class 'Z' overrides a number of these base class methods, then calls 'X'. There are also several versions of 'Z' each doing similar things but with subtle differences. Question: Is there a way of calling the overridden methods in the parent class 'Z' from the child 'X'...? Thanks in advance, Phil
"Rules are for the obedience of fools and the guidance of wise men"
-
I hope that sounds right? I will explain... I have built a class (lets call it 'X') that constructs a StringBuilder and then passes it back. All is OK except within this class it calls a number of methods from a base class higher up. Here comes the tricky bit. Class 'Z' overrides a number of these base class methods, then calls 'X'. There are also several versions of 'Z' each doing similar things but with subtle differences. Question: Is there a way of calling the overridden methods in the parent class 'Z' from the child 'X'...? Thanks in advance, Phil
"Rules are for the obedience of fools and the guidance of wise men"
Phillip Hodges wrote:
Is there a way of calling the overridden methods in the parent class 'Z' from the child 'X'...?
Yes, just call them. If they are declared as virtual in the base class and override in the derived class then the correct version will be called. i.e. The version defined in the concrete class. That is to say the version of the real object, not its base.
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." Ready to Give up - Your help will be much appreciated. My website
-
Phillip Hodges wrote:
Is there a way of calling the overridden methods in the parent class 'Z' from the child 'X'...?
Yes, just call them. If they are declared as virtual in the base class and override in the derived class then the correct version will be called. i.e. The version defined in the concrete class. That is to say the version of the real object, not its base.
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." Ready to Give up - Your help will be much appreciated. My website
Thanks for the quick response... Yeah, I made a silly mistake... It is working fine now... Thanks again, Phil
"Rules are for the obedience of fools and the guidance of wise men"
-
I hope that sounds right? I will explain... I have built a class (lets call it 'X') that constructs a StringBuilder and then passes it back. All is OK except within this class it calls a number of methods from a base class higher up. Here comes the tricky bit. Class 'Z' overrides a number of these base class methods, then calls 'X'. There are also several versions of 'Z' each doing similar things but with subtle differences. Question: Is there a way of calling the overridden methods in the parent class 'Z' from the child 'X'...? Thanks in advance, Phil
"Rules are for the obedience of fools and the guidance of wise men"
Phillip Hodges wrote:
lets call it 'X'
Actually, lets not - it just complicates things and takes therm out of context. Im sure you use a descriptive name in your code (like MyStringCreator or something) so why not use it here to help people understand the context in which you are writing code.