Basic Object Oriented Programming Concepts – Interview Questions


These Questions are common to C++, C#, Java Interviews. Questions are related to software design

1. What is Loosely Coupling in Object Oriented Programming or Software Design?
System should have as many dependencies as is needed to do their job - and the dependencies should be few.

2. What is the advantage of Loosely Coupling?
Loose Coupling helps in reusability, easier maintainability, and allows providing "mock" objects in expensive services as opposed to creating new objects.

3. What is a Concrete Object?
A concrete object is any object created with the keyword new.

4. What is Dependency Injection (DI) in Object Oriented Programming (OOP)?
This is also known as “Inversion of Control" (IoC). It refers to the process of supplying an external dependency in order to reduce more dependencies to a software component. This is implemented to achieve loosely coupling. Object's dependencies should be on interfaces but not on concrete objects.

5. What are the term SOLID stands in OOPs? Explain about it?
SOLID stands for Single Responsibility Open Closed Liskov Substitution Interface Segregation Dependency Inversion .
SOLID Principles of Object-Oriented Design, as introduced by Robert C Martin.
Single Responsibility Principle
A class (or method) should only have one reason to change.
Open Closed Principle
Extending a class shouldn't require modification of that class.
Liskov Substitution Principle
Derived classes must be substitutable for their base classes.
Interface Segregation Principle
Make fine grained interfaces that are client specific.
Dependency Inversion Principle
Program to the interface, not the implementation.
6. What is Single Responsibility Principle of a class?
There should never be more than one reason for a class to change. The classes should exist for one purpose only.

7. What are open closed principles of class?
Open Close Principle strictly says that the Software objects like classes, modules and functions should be open for extension but closed for modifications. The design and writing of the code should be done in a way such that new functionality should be added with minimum changes in the existing code. In other words the design should be done in a way to allow the adding of new functionality as new classes, keeping as much as possible existing code unchanged.

8. What is Liskov Substitution Principle?
Likov's Substitution Principle states that if a program module is using a Base class, then the reference to the Base class can be replaced with a Derived class without affecting the functionality of the program module. In other words derived types must be completely substitutable for their base types. For ex: If a person knows how to drive a car then he should be able to drive any type of car.

9. What is Interface Segregation Principle?
The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use. Instead of one fat interface many small interfaces are preferred based on groups of methods, each one serving one submodule.

10. What is Dependency Inversion Principle?
According to this principle the way of designing a class structure is to start from high level modules to the low level modules: High Level Classes --> Abstraction Layer --> Low Level Classes
High-level modules should not depend on low-level modules. Both should depend on abstractions.
Abstractions should not depend on details. Details should depend on abstractions.

    0 comments:

    Post a Comment