Let’s say you have a class called Customer.
What we will do with it?
Now let say there are some user interfaces called as EmployeeUI and ManagerUI which internally uses the Customer class and its functions.
Customer will demand a new UI from us called DirectorUI. Now this UI will also use Customer class and its functions.
But there is a problem. Update function is going to behave differently for this UI.
We will go and some if conditions in Update function and make it working for all previous UIs as well as this new UI?
Is it the correct way?
Why it is required to follow such principle?
Customer class is already used in 2 UIs and successfully tested and proved.
What is the correct solution?
- Make the existing Update function virtual.
- Create a new class called CustomerForDirector which will inherit from Customer Class.
- Override the virtual function in new class.
- Now in DirectorUI just use this new Derived class instead of Customer class.
Also read http://questpond.blog.com/2013/09/09/can-you-talk-about-abstraction-and-encapsulation-in-detail-net-c-and-oop-interview-questions-with-answers/