J
Jack Addington
I have a base form and a base logic class. Each has to know of the other.
I'm then inheriting to create descendant form and descendant logic which
extend both objects and again have to know of each other. I'm getting mixed
up in the syntax/technique on how to refer to the references generically in
the code. I want to be able to always call LogicClass.SomeMethod() and each
FormClass knows what to do with it. In some cases I have 3-4 levels deep.
I can't rationalize what exactly is happening or if its correct, even if
certain ways seem to work. I'm looking for a consistent manner since I seem
to code like this all over the place. Sometimes I seem to get mixed up with
trying to cast up or down... I'm getting quite confused.
1) Is this a waste of resources or does the base class variables not even
get created? I'm assuming then that if I always access throught the Logic
property in all the methods throughout both baseForm and childForm it will
always refer to the coresponding _logic (in the case of childForm the
BaseLogic _logic is never created???)
Class BaseForm{
protected BaseLogic _logic = new BaseLogic( );
public BaseLogic Logic { get{ return _logic;}}
class ChildForm : BaseForm{
protected new ChildLogic _logic = new ChildLogic( );
public new ChildLogic Logic { get{ return _logic;}}
}
Is it bad practice to instantiate the _logic in each inherited object? If I
don't I get stuck in ChildForm where I can't do a (ChildLogic)_logic type
operation...
2) With the example above when I call the following method that isn't
overriden in ChildForm what really happens?
Class BaseForm{
...
public void TestMethod(){
Logic.SomeMethod()
}
SomeOtherClass {
childForm = new ChildForm();
childForm.TestMethod()
}
which _logic does this use? It seems to me that it uses the
ChildForm._logic and as long as the ChildForm._logic has a SomeMethod
I've also tried other ways where I have a method to instatiate the logic
object and then I override the instatiate method in the descendent class.
That assures that I only create the deepest level descended logic objects.
Kinda long winded but I really could use some help..
thx
jack
I'm then inheriting to create descendant form and descendant logic which
extend both objects and again have to know of each other. I'm getting mixed
up in the syntax/technique on how to refer to the references generically in
the code. I want to be able to always call LogicClass.SomeMethod() and each
FormClass knows what to do with it. In some cases I have 3-4 levels deep.
I can't rationalize what exactly is happening or if its correct, even if
certain ways seem to work. I'm looking for a consistent manner since I seem
to code like this all over the place. Sometimes I seem to get mixed up with
trying to cast up or down... I'm getting quite confused.
1) Is this a waste of resources or does the base class variables not even
get created? I'm assuming then that if I always access throught the Logic
property in all the methods throughout both baseForm and childForm it will
always refer to the coresponding _logic (in the case of childForm the
BaseLogic _logic is never created???)
Class BaseForm{
protected BaseLogic _logic = new BaseLogic( );
public BaseLogic Logic { get{ return _logic;}}
class ChildForm : BaseForm{
protected new ChildLogic _logic = new ChildLogic( );
public new ChildLogic Logic { get{ return _logic;}}
}
Is it bad practice to instantiate the _logic in each inherited object? If I
don't I get stuck in ChildForm where I can't do a (ChildLogic)_logic type
operation...
2) With the example above when I call the following method that isn't
overriden in ChildForm what really happens?
Class BaseForm{
...
public void TestMethod(){
Logic.SomeMethod()
}
SomeOtherClass {
childForm = new ChildForm();
childForm.TestMethod()
}
which _logic does this use? It seems to me that it uses the
ChildForm._logic and as long as the ChildForm._logic has a SomeMethod
I've also tried other ways where I have a method to instatiate the logic
object and then I override the instatiate method in the descendent class.
That assures that I only create the deepest level descended logic objects.
Kinda long winded but I really could use some help..
thx
jack