c# - Cleaner way of abstraction -


I am reapplying some old code and thinking about a design decision

  AbstractClassA-Step 1 Step 2 - Step 2.1 - Step 2.2 - Stap 3   

Summary methods of the Abstract class Step 1, Step 2, and Step 3. Step 2 always Requirements to call on methods 2.1 2.2. But in the current design, Phase 2.1 and 2.2 have not been declared as abstract and it has been implemented and called in each heritage class. I am planning to reactivate the code by dragging all these methods (including 2.1 and 2.2) in one interface. I am then planning to implement an intangible class of this interface, which will call Phase 2, 2.1 and 2.2. But somehow it does not seem obvious, I want to know whether this design is faulty or not?

  Interface A -Step1 -Step2 -Step 2.1 -Step 2.2 -Step3    

It looks like what you are looking for will be: imyInterface {void Step1 (); Zero Step 2 (); Zero Step 3 (); } Summary class MyBaseClass: IMyInterface {public essence zero phase 1 (); Public Zero Stage 2 () {Stage 2_1 (); Step2_2 (); } Public essence zero phase 3 (); Protected abstract Zero Step 2_1 (); Protected abstract zero phase 2_2 (); }

Use an interface for intangible, when you want to mention something normally, where the precise examples used on the runtime can change. Use Base Class for Shared Implementation, so that you can define what can happen in step 2 and step 2.2 in each subclass, but your base class defines that step 2 is executing step 2.1 , Then step 2.2.

Comments