Showing posts with label Design Patterns. Show all posts
Showing posts with label Design Patterns. Show all posts

Friday, January 10, 2020

Design Patterns

A design patterns are well-proved solution for solving the specific problem/task.

When should we use the design patterns?

We must use the design patterns during the analysis and requirement phase of SDLC 
(Software Development Life Cycle).

Design patterns ease the analysis and requirement phase of SDLC by providing information

based on prior hands-on experiences.

Categorization of design patterns:
Basically, design patterns are categorized into two parts:
  1. Core Java (or JSE) Design Patterns.
  2. J2EE Design Patterns.
Core Java (OOPS) Design Patterns
In core java, there are mainly three types of design patterns, which are further divided into 
their sub-parts:

1.Creational Design Patterns
Creational design patterns provide solutions to instantiate an object in the best possible 
way for specific situations.

  1. Factory Pattern
  2. Abstract Factory Pattern
  3. Singleton Pattern
  4. Prototype Pattern
  5. Builder Pattern
2. Structural Design Patterns

Structural design patterns are used to simplify and manage the relationships between objects and classes. 

They help in creating compositions of objects to form larger structures while ensuring that 

these structures are flexible and easy to manage.

  1. Adapter Pattern
  2. Bridge Pattern
  3. Composite Pattern
  4. Decorator Pattern
  5. Facade Pattern
  6. Flyweight Pattern
  7. Proxy Pattern
3. Behavioral Design Patterns

Behavioral patterns provide a solution for better interaction between objects

and how to provide loose-coupling and flexibility to extend easily.


  1. Chain Of Responsibility Pattern
  2. Command Pattern
  3. Interpreter Pattern
  4. Iterator Pattern
  5. Mediator Pattern
  6. Memento Pattern
  7. Observer Pattern
  8. State Pattern
  9. Strategy Pattern
  10. Template Pattern
  11. Visitor Pattern



Monday, August 29, 2016

Java Design Pattern Interview questions

If two different class loaders load a singleton class, would they load it twice ?
Two objects loaded by different class loaders are never equal even if they carry the same values.
So, each class loader will have its own singleton.

What is Decorator design pattern?
The decorator design pattern attaches responsibilities to objects at runtime.
BufferedInputStream in java.io is an example of Decorator. It wraps around a InputStream and provide additional buffering functionality.

What is Strategy design pattern?
Strategy design pattern lets you swap new algorithms and processes into your program without
affecting the objects that use them.
AWT containers delegate the layout to layout managers. Layout managers use strategy pattern to for appropriate layout.

What is Iterator Design pattern?
 Iterator pattern is used to iterate over a collection sequentially and provide a way the access the individual elements.

What is Factory pattern?
 Factory pattern abstracts the object creation process from the code that uses the objects.

What is Front Controller design pattern?
Front controller suggest using a single servlet for centralizing request handling and delegating functions like validation and business process handling to helpers.

What is Composite view pattern?
A composite view is made of several sub-views.
A JSP page can use a header jsp, footer jsp etc.

What is View Helper pattern?
In this pattern, the view delegates processing responsibilities to helper classes.
Implemented using Javabeans.

Difference between Service to Worker pattern and Dispatcher View pattern.
Both pattern use Front controller combined with Helpers with Dispatcher component.
In Service to worker, front controller delegates content retrieval to View Helpers. Controller also takes care of tasks like authentication, authorization etc.
In Dispatcher View, Controller does not delegate content retrieval to helpers. Most of the work is done by views.