.NET interview questions: - Elaborate the advantages of using OOPS over functional programming?
- By Shiv Prasad Koirala in .Net
- Feb 23rd, 2012
- 9381
- 0
In fact this one is the basic but very important .NET interview questions asked in almost every interview. An interviewer expects that every candidate should know and answer it. So if you are not sure about it so read the following answer thoroughly and get clear your fundamental related to OOPS.
- Abstraction: - Abstraction filters un-necessary information from the user's perspective. It just gives enough information to the user rather than giving him unnecessary information by which he can get confused. Abstraction can be different from different user perspective. For instance below figure 'Abstraction perspective' shows how a simple user looks at a television and how a TV mechanic looks at the television. From a simple user perspective he only needs to start, stop, change channels and control volume. But when a TV mechanic looks at the box he is concerned with details like CRT, Electrical Components, Wires, connection, cooling fan etc. So abstraction is about two things one is show only what is needed and second the need should be from end users perspective.
Figure: - Abstraction Perspective
Ok, now how does that fit in to the software world? When we design components we should know what type of user will be using the component. Figure ‘Abstraction in action' shows how the customer components when has different view of abstraction for the internal and external developer.
Figure: - Abstraction in Action
- Encapsulation: - Encapsulation separates an object interface from its implementation. It hides internal implementation details from the users. You can get a better feel by looking at the figure ‘Encapsulation and Abstraction'. It shows a simple stock class which allows a user to add and remove products from the stock. It also has a restock and alert in case products are out of stock. End user is only exposed to operations like ‘addstock','removestock' and get the current level of the stock. He is completely isolated from auto functionalities like how the restock operation takes place. These operations are encapsulated from the end user perspective.
Note :- Abstraction means to expose the necessary functionalities while encapsulation means to hide the complexity. They both complement each other, but there is a huge difference in terms of thinking approach. In interviews ‘difference between abstraction and encapsulation' is one of the favorites questions among interviewers. So understand the concept fundamentally as you can get in to long talks of confusion with the interviewer.
Figure: - Encapsulation and Abstraction
In java or C# encapsulation is achieved by using private, public and protected access modifiers.
- Inheritance: - OOPS is all about mapping with real world. One of the relationships in real world is parent child relationship. Inheritance is a methodology by which you can form new classes using existing classes as base. For instance figure ‘Inheritance in action' shows we have created a parent class called as ‘ClsDisplay'. We can inherit from ‘clsDisplay' and create bold and italic display classes.
Figure: - Inheritance in action
- Polymorphism: - Polymorphism means one object can exist in different forms. It refers to ability of the object to take different forms depending on situations. For instance we can use the ‘clsDisplay' object to point to italic or a bold display object. So depending on the situation the parent class ‘clsDisplay' can morph/change to any other form.
Figure: - Polymorphism in action
See more on OOPS in video from describing implementation of Aggregation, Association and Composition as follows: -
Visit to get more stuff on Most asked Dotnet interview questions
Regards,
Also visit for more author's other blogs on important .NET interview questions
Shiv Prasad Koirala
Visit us @ www.questpond.com or call us at 022-66752917... read more