?

Log in

Previous Entry | Next Entry

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.

  Example:

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.
Example:

code 3

Old Clients
MyClass m=new MyClass();
m.MyMethod1();
m.MyMethod2();
m.MyMethod();

Client seeking change
MyClass m=new NewMyClass();
m.MyMethod1();
m.MyMethod2();
m.MyMethod();

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 www.sukesh-Marla.com or contact SukeshMarla@Gmail.com
Copy right www.questpond.com

Buy 600+ Real Time Interview Videos

Call +91-22-66752917 or mail us on questpond@questpond.com for more details on C#, .NET, ASP.NET, SQL Server interview question videos.

SQL Server interview question videos

Latest Month

January 2017
S M T W T F S
1234567
891011121314
15161718192021
22232425262728
293031    

Tags

Powered by LiveJournal.com