Gang Of Four Design Patterns

Q- What are the Gang of Four Design Patterns?

Creational Design Patterns:- Creational design patterns are concerned with the way of creating objects. These design patterns are used when a decision must be made at the time of instantiation of a class. This is useful to deal with object creation mechanisms, trying to create objects in a manner suitable to the situation.  Structural Design Patterns:- Structural design patterns are way how classes and objects can be composed, to form a larger structures.This patterns focus, how the classes inherit from each other and how they are composed from other classes.
The design patterns simplifies the structure by identifying the relationships.
This is useful to explain that how to objects and classes should be assemble into larger structures to make these structures flexible and efficient.
Behavioral Design Patterns:-Behavioral design patterns are the way to providing the solutions regarding objects interaction.
This is useful to focus on communication between objects. How one class communicates with others
This design patterns provide solutions to interaction and responsibility of objects.

Q- What is the differenc between facade and strategy design pattern?

Facade : Facade is structural design patterns. So we can say using facade we can design structer using interface and its implementation.
Strategy :  Strategy is behavior design patterns. So we can say using strategy we can design how the objects are communicate to each other.

Q- What is difference between Facade Design and bridge design pattern?

A bridge design pattern is created to seperate the implementation from the API. A bridge tends to be created to support pluggability of the implementation into different APIs.
A facade design pattern is used to create single interface by using set of design pattern. A facade is an API created on top of a set of APIs or methods. It provides the ability to interface with a single API where there are actually several.

Q- What is the difference between Adapter and Bridge Design Pattern?

Q- What is the difference between Strategy Design Pattern and Bridge Design Pattern?

Strategy Design Pattern is used for Behavioural decisions, while Bridge Design Pattern is used for Structural decisions. Brigde Pattern separats the abstract elements from the implementation details (to seperate the implementation from the API), while Strategy Pattern is concerned making algorithms more interchangeable.

Bridge: ( A structural pattern)
Bridge pattern decouples abstraction and implementation and allows both to vary independently.
Use this pattern when :
  • Abstractions and implementations on an API  not been decided at compile time
  • Abstractions and implementations of and API should be changed independently
  • Changes in implementation of abstraction should not affect in our application
  • Client should be insulated from implementation details.
Strategy: ( Behavioural pattern)
Strategy patterns enable you to switch between multiple algorithms from a family of algorithms at run time.
Use Strategy pattern when :
  • While multiple versions or multiple way of an algorithms are required
  • While we have to choose the behaviour of class changed dynamically at run time
  • To avoid conditional statements in an algorithms. 
Question : Difference between singleton class and singleton scope in spring ? 

Spring Singleton Scope : Singleton in Spring guarantees to create only one bean instance for given bean per id definition per container.  that means if we define same bean with two id or name than two instance world be created. Spring Singletone Scope Example

Spring singleton pattern is different from gang of four singleton pattern. While gang of four Singleton pattern ensures that one and only one instance is created per ClassLoader.




No comments:

Post a Comment