Filter by Tags
dot-net c-sharp

How to “properly” override a base class method?



2 0
This Question is asked to:

Whenever i override a method of a base class, other than my implementation of this method, i seem to have 3 choices.

1) Call base.Method(), and then provide my implementation.

2) Provide my implementation and then call base.Method()

3) Just provide my implementation.

Recently while using a library i have realized few bugs that were introduced because of not implementing the method as expected by the library. I am not sure if that is bad on part of library, or something wrong in my understanding.

I will take one example.

public class ViewManager {  public virtual void Customize(){  PrepareBaseView();  }  }    public class PostViewManager {  public override void Customize(){  base.Customize();  PreparePostView();  }  }      public class PreViewManager {  public override void Customize(){  PreparePreView();  base.Customize();  }  }      public class CustomViewManager {  public override void Customize(){  PrepareCustomView();  }  }

My question here is that how could a child class know (without taking a look at base class implementation) which order (or option) is being expected by the parent class? Is there a way in which parent class could enforce one of the three alternates to all the deriving classes?

Ravinder Singh
Posted on : Tue, Apr 12, 2016
Views : 743

Ask Question

If you want to ask question you must LogIn or SignUp
Login SignUp
To Add your Answer Please
LogIn | SignUp

Quick Links



Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..


Login to Open ESchool OR Create your account    Login   SignUp