C# Inheritance wrapper code -
public abstract class base { public void execute() { //'preexecute code' child.execute(); //'postexecute code' } } public class child : base { { public void execute() { //'some child specific code' } } is there way in c# support execution model above call function in child class base class. "preexecute code" , "postexecute code" common , should ran every time "execute" called.
i'd recommend abstract method invoked base (known template method pattern):
abstract class base { void foo() { dosomething(); bar(); dosomethingelse(); } protected abstract void bar(); } class child : base { protected override void bar() { dosomethingchildspecific(); } } you can implement specific part in bar (primitive operation in template method pattern) each child, , base invokes in right context. consumers can therefore not mess execution sequence foo, unlike if able override foo itself.
Comments
Post a Comment