c# - Object-oriented design riddle -


consider have abstract base class inheriting other class x.

class override method foo1.

there few other classes a1,a2,a3 concrete classes.

all concrete classes inherit method foo1.

method foo1 general algorithm should suitable concrete classes.
"almost" because of 1 exception in algorithm there if condition, of classes lets a1,a3 need luanch other method foo2 in start of foo.

for a2 don't need launch foo2.

the problem if if implement foo2 in class it's children inherit function well, not design?

i thought of excluding foo2 interface implemented concrete classes-> not foo1 calls foo2 on base class!

any ideas how solve problem in proper way?

thank you

the solution use in situation make layer of abstract classes classes need special foo2 derive instead.

abstract class : x {     public virtual void foo()     {         //foo logic     } }  abstract class b : {     protected virtual void foo2()     {         //foo2     }      override void foo()     {         foo2();         base.foo();     } }  public a1 : b { }  public a2 : { }  public a3 : b { } 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -