Click below for Step by Step and Interview Q & A (dotnetinter) wrote,
Click below for Step by Step and Interview Q & A

Can you explain change existing code without touching it?( .NET Interview questions)

If you looking for last minute .NET interview revision start from this

Let’s understand how we normally work first?

  1. We create class library with some functionality and reuse it at multiple places.


code 1

Note: Above code will be used by more than one client code.

     2.    Test our code
     3.    Deploy the application

Now sometime in the future we came across a situation where one of the client wants some changes in the MyMethod function and we start putting if condition inside the MyMethod function.

  • Now because I have made changes in MyMethod function I have to test all my existing clients along with one who was seeking a change in class library.

  • It also violates OCP – Open closed principle – Software modules should be closed for modifications but open for extensions.

Now the question is then what will be the best solution?
Answer is polymorphism.
At the time of creation of the class we should have anticipated such issue and we should have decorated our MyFunction method with virtual modifier.

code 2

Now whenever changes will be asked we can go and create new child class and MyClass and override and MyMethod function. Client Code which was seeking a change in the functionality will use new class.

code 3

Old Clients
MyClass m=new MyClass();

Client seeking change
MyClass m=new NewMyClass();

Recently one of our friends in a .NET interview was asked about the importance of yield keyword , below goes the explanation for the same.

Hope you understood the concept and enjoyed reading it. Don’t forget to subscribe us on facebook.

If you are looking for some technical training on any Microsoft technologies likeWCF,MVC,WCF,BI or any practices like Design Patterns, UML, DDD etc visit or contact
Tags: .net interview questions, .net yield interview questions, c# interview questions, csharp interview questions, it interview questions with answers, programming interview questions

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded