Design Patterns Interview questions basic

Design Patterns Interview questions basic
Design Patterns are best proven techniques for a common design problem.
It is only a design technique and not code. Though code is available for almost all design patterns in all popular languages, design patterns mean the design technique alone.
Each design pattern explains a repeated problem, gives standard solution to the problem.

Types of Patterns:Design Patterns are generally classified into three categories, they are:
1. Creational
2. Structural
3. Behavioral

1. CreationalThey deal with object creation. They provide you the best way to create objects based on the current situation.
Example:
Singleton, Factory method, Abstract factory, Builder

2. StructuralThey deal with relationship between entities. They provide you the best way to relate entities on various scenarios.
Example:
Adapter, Aggregate, Bridge

3. BehavioralThey deal with communication between objects. They provide you the best way to communicate between objects.
Example:
Chain of responsibility, Command, Interpreter

Further Classification: Though the above three are the major classification, one more category also exists which may be considered as a sub part of the above. It is:

ConcurrencyThey deal with multi-threaded programs. They provide solutions for multi-thread design problems.
Example:
Balking, Double checked locking, guarded suspension

OOP Techniques and Design Patterns:Before going into design patterns, we need to know some of the OOP (Object Oriented Programming) features, which will in turn lead to a better understanding of Design patterns.
Let us now see the OOPs features one by one,

Class: It defines characteristics of a thing and its behavior. It is blueprint from based on which objects are created.
Example: Employee (which will have all the details about the employee like name, id, salary, etc and the methods which describes his behavior like calcSalary(),displaydetails(),etc.

Object: Is an instance of a class. It will be exactly the same as a class but can be assigned values and used whereas a class can’t be used without creating objects.

Inheritance:
A feature in which the base class’s characteristics and behavior are derived to the child class also.
Types:
Single
Multiple

Single:
A class inherits from a single class.
Multiple:
A class inherits from more than 1 class.

Abstraction: “Abstraction is simplifying complex reality by modeling classes appropriate to the problem, and working at the most appropriate level of inheritance for a given aspect of the problem.” Is what the Wikipedia says.

Encapsulation: It is a feature which hides data and functions from others classes.

Polymorphism: A feature using which more than one definition is given to a single name. It can either be function polymorphism or operator overloading.

Association: Association defines a relationship between classes of objects which allows one object to cause another to perform an action on its behalf.

Composition:
Composition is a way to combine simple objects or data types into more complex ones.

Aggregation: Aggregation is a form of composition where one looks at the system as a whole rather than as parts. 

No comments: