baseclass and a interface.
-
Now : -abstract classA -inherited classB with interfaceX -inherited classC with interfaceX -inherited classD with interfaceX -sealed classX that calls interfaceX But a lot of the commands in interfaceX , could be directly handled by the base class. Only some of the commands in interfaceX , are specific enough to be handled by the inherited class. I think i want : -abstract classA with interfaceX -inherited classB overides interfaceX.commandC -inherited classC overides interfaceX.commandC -inherited classD overides interfaceX.commandC -sealed classX that calls interfaceX Am i right , or am i missing something ??
Jarno Burger Video Jockey
-
Now : -abstract classA -inherited classB with interfaceX -inherited classC with interfaceX -inherited classD with interfaceX -sealed classX that calls interfaceX But a lot of the commands in interfaceX , could be directly handled by the base class. Only some of the commands in interfaceX , are specific enough to be handled by the inherited class. I think i want : -abstract classA with interfaceX -inherited classB overides interfaceX.commandC -inherited classC overides interfaceX.commandC -inherited classD overides interfaceX.commandC -sealed classX that calls interfaceX Am i right , or am i missing something ??
Jarno Burger Video Jockey
If you want to use second design, abstract class needs to have virtual method of commandC. example:
public interface ITest
{
void Test();
}public class T1 : ITest
{
public T1(){}
public virtual void Test()
{
MessageBox.Show("From parent");
}
}public class T2 : T1
{
public T2(){}
public override void Test()
{
MessageBox.Show("And I am parent's baby");
}
}T1 t1 = new T1();
T2 t2 = new T2();
ITest tt1 = (ITest)t1;
ITest tt2 = (ITest)t2;
t1.Test();
t2.Test();
tt1.Test();
tt2.Test();In the end both design method woud work. In your case i would chose the second. But it is up to you to chose
-
Now : -abstract classA -inherited classB with interfaceX -inherited classC with interfaceX -inherited classD with interfaceX -sealed classX that calls interfaceX But a lot of the commands in interfaceX , could be directly handled by the base class. Only some of the commands in interfaceX , are specific enough to be handled by the inherited class. I think i want : -abstract classA with interfaceX -inherited classB overides interfaceX.commandC -inherited classC overides interfaceX.commandC -inherited classD overides interfaceX.commandC -sealed classX that calls interfaceX Am i right , or am i missing something ??
Jarno Burger Video Jockey
I think that would be the way to go. I would also declare commandC in classA as abstract and force an override. Alternative: If you have a lot of commands that would have to overridden, you would want to use interface inheritance. -interfaceX would not have the definition for commandC. -You could then create interfaceY that inherits interfaceX and define commandC. -Classes B-D would inherit classA and implement interfaceY. -In classX you would call interfaceY. The only problem with your method: If you later change the definition of interfaceX you would have to change all the classes (classA would have to be modified even though there is no real change). This would also be true if you wanted to add a method. It all depends on the size of your classes/interface and how often they will change.
-
I think that would be the way to go. I would also declare commandC in classA as abstract and force an override. Alternative: If you have a lot of commands that would have to overridden, you would want to use interface inheritance. -interfaceX would not have the definition for commandC. -You could then create interfaceY that inherits interfaceX and define commandC. -Classes B-D would inherit classA and implement interfaceY. -In classX you would call interfaceY. The only problem with your method: If you later change the definition of interfaceX you would have to change all the classes (classA would have to be modified even though there is no real change). This would also be true if you wanted to add a method. It all depends on the size of your classes/interface and how often they will change.
thanx , you both cleaned my perspective with those abstract concepts !
Jarno Burger Video Jockey