Force a Method

  • Thread starter Thread starter Arran Pearce
  • Start date Start date
A

Arran Pearce

Hi,

If i have a abstract class (e.g. Class1) and then i make Class2 which
inherits from Class1. I have a method in Class1 which i want to force
Class2 to run at some point. Is there a way i can force this? I dont want
to run the method in the constructor of Class1 as the Constructor needs to
do some work in Class2 before the method will work correctly.

thanks

Arran
 
Yes that is what i am currently doing...which is fine. But i was wondering
if there was a way to force a class to run the method.
I would not be the only developer using the base class, so it would seem to
me to be good practise to force it somehow.
 
By force it, do you mean that you don't want them to run any other methods
until this one method has been executed?

Or do you mean that you'll somehow guarantee that it'll be called before
other methods are called?

It seems to me that you need to set an Initialized flag of some kind in this
method, and check that flag at the beginning of every method call. You
could possibly do this more neatly with a custom attribute.

John
 
Back
Top