By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,505 Members | 1,165 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,505 IT Pros & Developers. It's quick & easy.

Force a Method

P: n/a
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
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
So run it at the end of the constructor in class2?

"Arran Pearce" <ar**********@bacoll.ac.uk> wrote in message
news:uo**************@tk2msftngp13.phx.gbl...
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

Nov 15 '05 #2

P: n/a
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.
"John Wood" <jwood8@go_ahead_remove_this.optonline.net> wrote in message
news:0u*********************@news4.srv.hcvlny.cv.n et...
So run it at the end of the constructor in class2?

"Arran Pearce" <ar**********@bacoll.ac.uk> wrote in message
news:uo**************@tk2msftngp13.phx.gbl...
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


Nov 15 '05 #3

P: n/a
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

"Arran Pearce" <ar**********@bacoll.ac.uk> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
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.
"John Wood" <jwood8@go_ahead_remove_this.optonline.net> wrote in message
news:0u*********************@news4.srv.hcvlny.cv.n et...
So run it at the end of the constructor in class2?

"Arran Pearce" <ar**********@bacoll.ac.uk> wrote in message
news:uo**************@tk2msftngp13.phx.gbl...
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



Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.