D
Dan
I have a need to make a set of classes that all share the same public
methods, some implementation and some data. So, I made an abstract
base (BaseClass) with an interface (IBaseClass) and a handful of
inherited classes. The static method calls the ctor of the appropriate
inherited class and returns it as type IBaseClass. There are no new
methods or properties in the inherited classes and public clients never
need to know which inherited class they have. From reading some posts
on this board I think I may have gone the wrong way here. Maybe I
should make BaseClass not abstract and plug in classes representing
different implementations. The code would not be all that different
(rearrange some stuff) because the plug-ins would be mostly the same as
the inherited members now. So, I'm curious if there are any design
gurus who would like share an opinion on this.
Current Design (drastically simplified)
interface IBaseClass
{
void DoStuff();
}
public abstract BaseClass : IBaseClass
{
static IBaseClass MakeIBaseClass(string behaviorInfo)
{
switch (behaviorInfo)
{
case "A":
return new InhA() as IBaseClass;
break;
case "B":
return new InhB() as IBaseClass;
break;
}
public void DoStuff()
{
//Do common stuff
_DoStuff()
}
protected abstract void _DoStuff()
}
And to keep this from going on forever, I'm sure you can see the
inherited classes (InhA, InhB, etc.) would have their own
implementations of _DoStuff. They also override some public base
properties, hold some of their own data and have different ctors.
Should I go to a plug-in (I guess delegation/containment) design over
this? Any advice would be greatly appreciated.
TIA,
Dan
methods, some implementation and some data. So, I made an abstract
base (BaseClass) with an interface (IBaseClass) and a handful of
inherited classes. The static method calls the ctor of the appropriate
inherited class and returns it as type IBaseClass. There are no new
methods or properties in the inherited classes and public clients never
need to know which inherited class they have. From reading some posts
on this board I think I may have gone the wrong way here. Maybe I
should make BaseClass not abstract and plug in classes representing
different implementations. The code would not be all that different
(rearrange some stuff) because the plug-ins would be mostly the same as
the inherited members now. So, I'm curious if there are any design
gurus who would like share an opinion on this.
Current Design (drastically simplified)
interface IBaseClass
{
void DoStuff();
}
public abstract BaseClass : IBaseClass
{
static IBaseClass MakeIBaseClass(string behaviorInfo)
{
switch (behaviorInfo)
{
case "A":
return new InhA() as IBaseClass;
break;
case "B":
return new InhB() as IBaseClass;
break;
}
public void DoStuff()
{
//Do common stuff
_DoStuff()
}
protected abstract void _DoStuff()
}
And to keep this from going on forever, I'm sure you can see the
inherited classes (InhA, InhB, etc.) would have their own
implementations of _DoStuff. They also override some public base
properties, hold some of their own data and have different ctors.
Should I go to a plug-in (I guess delegation/containment) design over
this? Any advice would be greatly appreciated.
TIA,
Dan