Module 3 Design Patterns
Module 3 Design Patterns
Design Patterns
A design patterns are well-proved solution for solving the
specific problem/task.
Core Java Design Patterns
Problem In core java, there are mainly three types of design patterns,
Suppose you want to create a class for which only a single which are further divided into their sub-parts:
instance (or object) should be created and that single object
can be used by all other classes.
1. Creational Design Pattern
Solution: 2. Factory Pattern
Singleton design pattern is the best solution of above 3. Abstract Factory Pattern
specific problem. So, every design pattern has some 4. Singleton Pattern
specification or set of rules for solving the problems.
5. Prototype Pattern
By using the design patterns you can make your code more
flexible, reusable and maintainable. It is the most important 6. Builder Pattern.
part because java internally follows design patterns.
2. Structural Design Pattern
Advantage of design pattern: 1. Adapter Pattern
1. They are reusable in multiple projects. 2. Bridge Pattern
2. They provide the solutions that help to define the 3. Composite Pattern
system architecture.
4. Decorator Pattern
3. They capture the software engineering
5. Facade Pattern
experiences.
6. Flyweight Pattern
4. They provide transparency to the design of an
application. 7. Proxy Pattern
5. They are well-proved and testified solutions since
they have been built upon the knowledge and 3. Behavioral Design Pattern
experience of expert software developers.
1. Chain Of Responsibility Pattern
6. Design patterns do not guarantee an absolute
solution to a problem. They provide clarity to the 2. Command Pattern
system architecture and the possibility of building 3. Interpreter Pattern
a better system 4. Iterator Pattern
5. Mediator Pattern
When should we use the design patterns? 6. Memento Pattern
7. Observer Pattern
We must use the design patterns during the analysis and 8. State Pattern
requirement phase of SDLC (Software Development Life 9. Strategy Pattern
Cycle). 10. Template Pattern
11. Visitor Pattern
Design patterns ease the analysis and requirement phase of
SDLC by providing information based on prior hands-on
experiences. 1. Creational design patterns
Categorization of 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
Basically, design patterns are categorized into two parts:
(i.e. creating an object of a class).
Advantage of Abstract Factory Pattern The structural design patterns simplify the structure by
o Abstract Factory Pattern isolates the client code identifying the relationships.
from concrete (implementation) classes.
o It eases the exchanging of object families. These patterns focus on, how the classes inherit from each
o It promotes consistency among objects. other and how they are composed from other classes.
Usage:
3. Behavioral Design Patterns o When the change of a state in one object must be
reflected in another object without keeping the
Behavioral design patterns are concerned with the objects tight coupled.
interaction and responsibility of objects. o When the framework we writes and needs to be
enhanced in future with new observers with
In these design patterns, the interaction between the minimal changes.
objects should be in such a way that they can easily talk
to each other and still should be loosely coupled.
3.3 Model view controller design pattern
That means the implementation and the client should be
loosely coupled in order to avoid hard coding and The Model-View-Controller (MVC) is a well-known design
dependencies. pattern in the web development field.
It is way to organize our code. It specifies that a program or
application shall consist of data model, presentation
information and control information. The MVC pattern
needs all these components to be separated as different
objects.