SlideShare a Scribd company logo
Presentation on
Design Patterns
Team : Boolean Poltergeist
What is Design Pattern?
A D E S I G N P A T T E R N I S A G E N E R A L R E U S A B L E
S O L U T I O N T O A C O M M O N L Y O C C U R R I N G P R O B L E M
I N S O F T W A R E D E S I G N .
Classification of Design Patterns
Mediator Design Pattern
201-15-3339
MD. SAKIBUZZAMAN ALIF
The Mediator defines the interface for
communication between objects. This is a
behavioural pattern as it defines a manner for
controlling communication between classes or
entities. The mediator pattern is used to reduce
coupling between classes that communicate with
each other.
Brief Description:
DIAGRAM
Implementation
1. Mediator
i)This component defines an interface for
communicating with Colleague objects.
2. ConcreteMediator
i) This component implements cooperative
behavior by coordinating Colleague objects.
ii)It knows and maintains its colleagues.
3. Colleague classes
i) Each Colleague class knows its Mediator object.
ii) Each colleague communicates with its mediator whenever it
would have otherwise communicated with another colleague.
Code Example
public abstract Colleague{
private Mediator mediator;
public Colleague(Mediator m)
{
mediator = m;
}
Colleage interface
public void send(String
message) {
mediator.send(message,
this);
}
send a message via the mediator
//Mediator interface
public interface Mediator
{
public void send(String
message, Colleague
colleague);
}
Mediator interface
public Mediator
getMediator() {return
mediator;}
public abstract void
receive(String message);
}
get access to the mediator
public class ApplicationMediator implements Mediator {
private ArrayList<Colleague> colleagues;
public ApplicationMediator() {
colleagues = new ArrayList<Colleague>();
}
public void addColleague(Colleague colleague) {
colleagues.add(colleague);
}
public void send(String message, Colleague originator) {
//let all other screens know that this screen has changed
for(Colleague colleague: colleagues) {
//don't tell ourselves
if(colleague != originator) {
colleage.receive(message);
}
}
}
}
Code Example
public class HeadDepartment
implements Department {
public class ConcreteColleague
extends Colleague {
public void receive(String
message) {
System.out.println("Colleague
Received: " + message);
}
}
public class MobileColleague extends
Colleague {
public void receive(String message) {
System.out.println("Mobile Received:
" + message);
}
} public class Client {
public static void main(String[] args) {
ApplicationMediator mediator = new
ApplicationMediator();
ConcreteColleague desktop = new
ConcreteColleague(mediator);
ConcreteColleague mobile = new
MobileColleague(mediator);
mediator.addColleague(desktop);
mediator.addColleague(mobile);
desktop.send("Hello World");
mobile.send("Hello");
}
}
PROS AND CONS
Its one of the main advantage is that we can
replace one object in the implementation
with a different other object without
affecting the classes and the interfaces.
Mediator Design Pattern is very simple to
understand and implement in real life
examples such as chatRoom, Facebook, Air
traffic control, Road traffic control etc.
Disadvantage of Mediator pattern is that it
centralises the communications between
various components and thus the mediator
pattern deals complexity of interaction for
complexity in the mediator. Because a
mediator hides protocols, it can become
more and more complex than any
individual colleague. This can make the
mediator itself a large block that is hard to
maintain.
Examples where
Mediator pattern is
used
Join Facebook Group
Air Traffic Control System
Iterator Pattern
201-15-3186
By :
Md. Shahin Alam
Iterator is a behavioral design pattern that lets you
traverse elements of a collection without exposing
its underlying representation (list, stack, tree, etc.).
Brief Description:
Declare the iterator interface.
Implement concrete iterator
classes for the collections that you
want to be traversable with
iterators.
Implement the collection interface
in your collection classes.
Step 1
Declare the collection interface and
describe a method for fetching
iterators.
Step 2
Step 3
Step 4
Implementation
Step 5
Go over the client code to replace all
of the collection traversal code with
the use of iterators.
Code Diagram
Code Example
public interface Iterator
{
boolean hasNext();
String Next();
}
public interface TV {
Iterator getIterator();
}
public class ConcreteIterator implements Iterator{
int index=0;
@Override
public boolean hasNext() {
if (index < channels.length)
return true;
return false;
}
@Override
public String Next() {
if(hasNext()) {
return channels[index++];
}
return null;
}
public class ConcreteTV implements TV{
private String[] channels = {"NTV", "GTV", "GB"};
private Iterator iterator;
public ConcreteTV() {
iterator= new ConcreteIterator();
}
@Override
public Iterator getIterator() {
return iterator;
}
Iterator.java TV.java
ConcreteIterator ConcreteTV.java
Code Example
public class Demo {
public static void main(String[] args) {
TV tv = new ConcreteTV();
Iterator iterator = tv.getIterator();
while (iterator.hasNext()) {
String channel = iterator.Next();
System.out.println("TV is Playing "+channel);
}
}
}
Demo.java
PROS AND CONS
We can iterate over the same collection in
parallel because each iterator object
contains its own iteration state.
Open/Closed Principle.
Single Responsibility Principle.
Using an iterator may be less efficient than
going through elements of some
specialized collections directly.
Applying the pattern can be an overkill if
your app only works with simple
collections.
Examples where
Iterate pattern is used
TV Remote
A good example of an Iterator is
a TV remote, which has the “next”
and “previous” buttons to surf TV
channels.
Media Players
In media players, we have a list of songs
listed and we can play the song by
traversing to the songs list and select
desired song. It’s also an iterator example.
Bridge Pattern
201-15-3220
By :
Yousuf Rayhan Emon
Bridge is a structural design pattern that lets
you split a large class or a set of closely related
classes into two separate hierarchies—
abstraction and implementation—which can be
developed independently of each other.
Brief Description:
first what operations the client needs and define them in the base abstraction
class.
Declare the ones that the abstraction needs in the general implementation
interface.
For all platforms in the domain create concrete implementation classes, but make
sure they all follow the implementation interface.
Inside the abstraction class, add a reference field for the implementation type.
If there have several variants of high-level logic, create refined abstractions for
each variant by extending the base abstraction class.
The client code should pass an implementation object to the abstraction’s
constructor to associate one with the other.
Implementation
DIAGRAM
Code Example with any language with Diagram :
Color.java
public interface Color {
String fill();
}
Implementcolor.java
public class Blue implements Color {
@Override
public String fill() {
return "Color is Blue";
}
}
Shape.java
public abstract class Shape {
protected Color color;
abstract public String draw();
}
extendShape.java
public class Square extends Shape {
public Square(Color color) {
super(color);
}
@Override
public String draw() {
return "Square drawn. " + color.fill();
}
}
test.java
@Test
public void whenBridgePatternInvoked_thenConfigSuccess()
{
Shape square = new Square(new Red());
assertEquals(square.draw(), "Square drawn. Color is Red");
}
Code Steps :
Pros and Cons of the pattern :
It can create platform-
independent classes and apps.
The client code works with high-
level abstractions. It isn’t exposed
to the platform details.
It can introduce new abstractions
and implementations
independently from each other.
Pros :
it might make the code more
complicated by applying the
pattern to a highly cohesive
class.
Cons :
Examples where Iterate
pattern is used:
For Retail shop owner
For software developer
If you are a software
developer and if you are
using some software for
writing some data, you could
just call an API for doing the
job.
If you are a retail shop owner and you send
a message to the customers regarding the
new products whenever they arrive at the
shop. So, you need to intimate the
customers via SMS. You will use some
software for doing that job. You click on
send the message with the help of that
software.
Design Patterns -
Decorator Pattern
201-15-3277
By :
Ahmed Ishtiak Nihal
Decorator is a design pattern that allows you to
attach additional behaviors to objects by enclosing
them in special wrapper objects that contain the
behaviors.
Brief Description:
IMPLEMANTION
WITH (DIAGRAM)
Ascertain that your company's domain may be represented
as a major component with several optional layers layered
on top of it.
AAI | Pro X
Figure out what methods are common to both the primary
component and the optional layers. Create a component
interface and declare those methods there.
Create a concrete component class in which to define the
base behavior.
Make a decorator base class. It should provide a field for
storing a wrapped object reference.
Ascertain that all classes adhere to the component
interface.
Create concrete decorators by extending them from the
base decorator.
The client code must be responsible for creating decorators
and composing them in the way the client needs.
W E ' L L M A K E A S H A P E I N T E R F A C E A S W E L L A S C O N C R E T E
C L A S S E S T H A T I M P L E M E N T T H E S H A P E I N T E R F A C E .
A F T E R T H A T , W E ' L L M A K E A N A B S T R A C T D E C O R A T O R C L A S S
C A L L E D S H A P E D E C O R A T O R T H A T I M P L E M E N T S T H E S H A P E
I N T E R F A C E A N D H A S A S H A P E O B J E C T A S A N I N S T A N C E
V A R I A B L E .
R E D S H A P E D E C O R A T O R I S A C O N C R E T E C L A S S I M P L E M E N T I N G
S H A P E D E C O R A T O R .
D E C O R A T O R P A T T E R N D E M O , O U R D E M O C L A S S W I L L U S E
R E D S H A P E D E C O R A T O R T O D E C O R A T E S H A P E O B J E C T S .
CODE EXAMPLE
WITH DIAGRAM
Shape.java
public interface Shape {
void draw();
}
Step 1
Step 2 Rectangle.java
public class Rectangle implements Shape {
@Override
public void draw() {
System.out.println("Shape: Rectangle");
}
}
Step 2 Circle.java
public class Circle implements Shape {
@Override
public void draw() {
System.out.println("Shape: Circle");
}
}
Step 3 ShapeDecorator.java
public abstract class ShapeDecorator implements Shape
{
protected Shape decoratedShape;
public ShapeDecorator(Shape decoratedShape){
this.decoratedShape = decoratedShape;
}
public void draw(){
decoratedShape.draw();
}
}
Step 4 RedShapeDecorator.java
public class RedShapeDecorator extends ShapeDecorator {
public RedShapeDecorator(Shape decoratedShape) {
super(decoratedShape);
}
@Override
public void draw() {
decoratedShape.draw();
setRedBorder(decoratedShape);
}
private void setRedBorder(Shape decoratedShape){
System.out.println("Border Color: Red");
}
}
Step 5 DecoratorPatternDemo.java
public class DecoratorPatternDemo {
public static void main(String[] args) {
Shape circle = new Circle();
Shape redCircle = new RedShapeDecorator(new Circle());
Shape redRectangle = new RedShapeDecorator(new Rectangle());
System.out.println("Circle with normal border");
circle.draw();
System.out.println("nCircle of red border");
redCircle.draw();
System.out.println("nRectangle of red border");
redRectangle.draw();
}
}
PROS AND CONS
You can change the behavior of an
object without creating a new
subclass.
At runtime, you can add or remove
responsibilities from an object.
Wrapping an object in numerous
decorators allows you to mix multiple
behaviors.
Principle of a single point of
responsibility. A monolithic class that
implements several possible behavior
variants can be broken down into
several smaller classes.
Pros :
It's difficult to remove a
specific wrapper from the
stack of wrappers.
It's difficult to create a
decorator whose behavior
is independent of the
sequence in which the
decorators are stacked.
The initial configuration
code of layers might look
pretty ugly.
Cons :
A N A S S A U L T G U N I S A D E A D L Y W E A P O N O N I T S O W N . B U T
Y O U C A N A P P L Y C E R T A I N " D E C O R A T I O N S " T O M A K E I T
M O R E A C C U R A T E , S I L E N T A N D D E V A S T A T I N G .
T H E D E C O R A T O R A T T A C H E S A D D I T I O N A L
R E S P O N S I B I L I T I E S T O A N O B J E C T D Y N A M I C A L L Y . T H E
O R N A M E N T S T H A T A R E A D D E D T O P I N E O R F I R T R E E S A R E
E X A M P L E S O F D E C O R A T O R S . L I G H T S , G A R L A N D , C A N D Y
C A N E S , G L A S S O R N A M E N T S , E T C . , C A N B E A D D E D T O A
T R E E T O G I V E I T A F E S T I V E L O O K . T H E O R N A M E N T S D O
N O T C H A N G E T H E T R E E I T S E L F W H I C H I S R E C O G N I Z A B L E
A S A C H R I S T M A S T R E E R E G A R D L E S S O F P A R T I C U L A R
O R N A M E N T S U S E D . A S A N E X A M P L E O F A D D I T I O N A L
F U N C T I O N A L I T Y , T H E A D D I T I O N O F L I G H T S A L L O W S O N E
T O " L I G H T U P " A C H R I S T M A S T R E E .
Examples where
Decorator pattern is used
Composite Pattern
201-15-3303
MD Saimur Rahman Swarnab
Composite is a structural design pattern that
lets you compose objects into tree structures
and then work with these structures as if they
were individual objects.
Brief Description:
Create a leaf class to represent
simple elements. A program may
have multiple different leaf classes.
Create a container class to represent
complex elements. In this class, provide
an array field for storing references to
sub-elements.
Step 1
Make sure that the core model of
your app can be represented as a
tree structure.
Step 2
Step 3
Step 4
Implementation
Step 5
Finally, define the methods for adding
and removal of child elements in the
container.
Implement concrete iterator classes
for the collections that you want to
be traversable with iterators.
UML DIAGRAM OF
CODE
Code Example
public class FinancialDepartment implements Department
{
private Integer id;
private String name;
public void printDepartmentName() {
System.out.println(getid().getSimpleName());
}
// standard constructor, getters, setters
}
public interface
Department {
void
printDepartmentName();
}
Department
FinancialDepartment
public class SalesDepartment implements Department {
private Integer id;
private String name;
public void printDepartmentName() {
System.out.println(getid().getSimpleName());
}
// standard constructor, getters, setters
}
SalesDepartment
Code Example
public class HeadDepartment implements Department {
private Integer id;
private String name;
private List<Department> childDepartments;
public HeadDepartment(Integer id, String name) {
this.id = id;
this.name = name;
this.childDepartments = new ArrayList<>();
}
public void printDepartmentName() {
childDepartments.forEach(Department::printDepartmentName);
}
public void addDepartment(Department department) {
childDepartments.add(department);
}
public void removeDepartment(Department department) {
childDepartments.remove(department);
}
}
public class CompositeDemo {
public static void main(String args[]) {
Department salesDepartment = new SalesDepartment(
1, "Sales department");
Department financialDepartment = new FinancialDepartment(
2, "Financial department");
HeadDepartment headDepartment = new HeadDepartment(
3, "Head department");
headDepartment.addDepartment(salesDepartment);
headDepartment.addDepartment(financialDepartment);
headDepartment.printDepartmentName();
}
}
}
HeadDepartment
CompositeDemo
PROS AND CONS
Open/Closed Principle. You can introduce
new element types into the app without
breaking the existing code, which now works
with the object tree.
You can work with complex tree structures
more conveniently: use polymorphism and
recursion to your advantage.
It might be difficult to provide a common
interface for classes whose functionality
differs too much. In certain scenarios,
you’d need to overgeneralize the
component interface, making it harder to
comprehend.
Examples where
Iterate pattern is used
Directory structure in file
system implementations
Group messaging
Template Pattern
201-15-3153
Nahidul Islam
The Template Method pattern provides a method in a super-class,
usually an abstract super-class, and defines the skeleton of an
operation in terms of several high-level steps.
Generally, these steps are implemented by additional helper methods
in the same class as the template method.
Brief Description:
Implementation :
We are going to create a Game abstract class defining
operations with a template method set to be final so that it
cannot be overridden. Cricket and Football are concrete classes
that extend Game and override its methods.
TemplatePatternDemo, our demo class, will use Game to
demonstrate use of template pattern.
Diagram :
Code :
Step 1
Create an abstract class with a
template method being final.
Game.java
public abstract class Game {
abstract void initialize();
abstract void startPlay();
abstract void endPlay();
//template method
public final void play(){
//initialize the game
initialize();
//start game
startPlay();
//end game
endPlay();
}
}
Step 2
Create concrete classes extending the above class.
Cricket.java
public class Cricket extends Game {
@Override
void endPlay() {
System.out.println("Cricket Game Finished!");
}
@Override
void initialize() {
System.out.println("Cricket Game Initialized! Start playing.");
}
@Override
void startPlay() {
System.out.println("Cricket Game Started. Enjoy the game!");
}
}
Football.java
public class Football extends Game {
@Override
void endPlay() {
System.out.println("Football Game Finished!");
}
@Override
void initialize() {
System.out.println("Football Game Initialized! Start
playing.");
}
@Override
void startPlay() {
System.out.println("Football Game Started. Enjoy the
game!");
}
}
Step 3
Use the Game's template method play() to demonstrate a defined way of
playing game.
TemplatePatternDemo.java
public class TemplatePatternDemo {
public static void main(String[] args) {
Game game = new Cricket();
game.play();
System.out.println();
game = new Football();
game.play();
}
}
Step 4
Verify the output.
Cricket Game Initialized! Start playing.
Cricket Game Started. Enjoy the game!
Cricket Game Finished!
Football Game Initialized! Start playing.
Football Game Started. Enjoy the game!
Football Game Finished!
PROS AND CONS
Pros:
1. Easy to Implement
and readable
2. Flexible.
3. Clear Architecture
Cons:
1. Enforce a particular
Design
2. Maintenance Issue
1. Daily Routine of a Worker
Example
2. Prepared Coffee
Nur-A-Alam Siddiqi
ID: 201-15-3274
Sheikh Fahim Karzon
ID: 201-15-3459
Singleton Pattern
Singleton pattern is one of the simpleest design
patterns in java. This type of design pattern comes
under creational pattern as the pattern provides
one of the best ways to creat an object
Brief Description:
Implementation with diagram
Code Examples
Eager Mode:
Lazy Mode:
Lazy Mode:
Pros and coins
You can be sure that a class has only a
single instance.
You gain a global access point to
that instance.
The singleton object is initialized only
when it’s requested for the first time.
Violates the Single Responsibility
Principle. The pattern solves two
problems at the time.
The Singleton pattern can mask
bad design, for instance, when the
components of the program know
too much about each other.
The pattern requires special
treatment in a multithreaded
environment so that multiple threads
won’t create a singleton object
several times.
Singleton pattern used
It is used where only a single instance of a class is
required to control the action throughout the execution
Singleton Pattern Used in Java Stand Library
1.
Singleton Pattern Used in driver objects
2.
Md. Shahin Alam
ID:201-15-3186
Ahmed Ishtiak Nihal
ID:201-15-3277
Yousuf Rayhan Emom
ID:201-15-3220
MD Saimur Rahman Swarnab
ID:201-15-3303
Team member
Md. Sakibuzzzman Alif
ID:201-15-3339
Nahidul Islam
ID:201-15-3153
Sheikh Fahim Karzon
ID:201-15-3459
Nur -A- Alom siddiqi
ID:201-15-3274
Team member
That's all
about our
presentation

More Related Content

What's hot

Ranjeet Mishra_JAVA_3+year exp
Ranjeet Mishra_JAVA_3+year expRanjeet Mishra_JAVA_3+year exp
Ranjeet Mishra_JAVA_3+year expRanjeet Mishra
 
Ratnesh_JavaJ2ee_3years exp
Ratnesh_JavaJ2ee_3years expRatnesh_JavaJ2ee_3years exp
Ratnesh_JavaJ2ee_3years expRatnesh Singh
 
CS6611 Mobile Application Development Lab Manual-2018-19
CS6611 Mobile Application Development Lab Manual-2018-19CS6611 Mobile Application Development Lab Manual-2018-19
CS6611 Mobile Application Development Lab Manual-2018-19
Gobinath Subramaniam
 
SDET_C#.NET_3_2_ years
SDET_C#.NET_3_2_ yearsSDET_C#.NET_3_2_ years
SDET_C#.NET_3_2_ yearsarunkumar hm
 
Webinar on Design Patterns titled 'Dive into Design Patterns'
Webinar on Design Patterns titled 'Dive into Design Patterns'Webinar on Design Patterns titled 'Dive into Design Patterns'
Webinar on Design Patterns titled 'Dive into Design Patterns'
Edureka!
 
Software Engineer CV with 3 year Experience.
Software Engineer CV with 3 year Experience.Software Engineer CV with 3 year Experience.
Software Engineer CV with 3 year Experience.Bhanu Pratap Yadav
 
Resume
ResumeResume
Modern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design PatternsModern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design Patterns
Volodymyr Voytyshyn
 
AmolVaidya _Anshul
AmolVaidya _AnshulAmolVaidya _Anshul
AmolVaidya _AnshulAmol Vaidya
 
Aman bansal
Aman bansalAman bansal
Aman bansal
Aman Bansal
 
POS 408 Extraordinary Life/newtonhelp.com 
POS 408 Extraordinary Life/newtonhelp.com POS 408 Extraordinary Life/newtonhelp.com 
POS 408 Extraordinary Life/newtonhelp.com 
myblue39
 
Vikramjit_Resume
Vikramjit_Resume Vikramjit_Resume
Vikramjit_Resume Rohan Saha
 

What's hot (17)

Om_Resume
Om_ResumeOm_Resume
Om_Resume
 
Ranjeet Mishra_JAVA_3+year exp
Ranjeet Mishra_JAVA_3+year expRanjeet Mishra_JAVA_3+year exp
Ranjeet Mishra_JAVA_3+year exp
 
Ratnesh_JavaJ2ee_3years exp
Ratnesh_JavaJ2ee_3years expRatnesh_JavaJ2ee_3years exp
Ratnesh_JavaJ2ee_3years exp
 
CS6611 Mobile Application Development Lab Manual-2018-19
CS6611 Mobile Application Development Lab Manual-2018-19CS6611 Mobile Application Development Lab Manual-2018-19
CS6611 Mobile Application Development Lab Manual-2018-19
 
SDET_C#.NET_3_2_ years
SDET_C#.NET_3_2_ yearsSDET_C#.NET_3_2_ years
SDET_C#.NET_3_2_ years
 
Raghav_thakkar
Raghav_thakkarRaghav_thakkar
Raghav_thakkar
 
Webinar on Design Patterns titled 'Dive into Design Patterns'
Webinar on Design Patterns titled 'Dive into Design Patterns'Webinar on Design Patterns titled 'Dive into Design Patterns'
Webinar on Design Patterns titled 'Dive into Design Patterns'
 
Software Engineer CV with 3 year Experience.
Software Engineer CV with 3 year Experience.Software Engineer CV with 3 year Experience.
Software Engineer CV with 3 year Experience.
 
Resume
ResumeResume
Resume
 
Modern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design PatternsModern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design Patterns
 
AmolVaidya _Anshul
AmolVaidya _AnshulAmolVaidya _Anshul
AmolVaidya _Anshul
 
Aman bansal
Aman bansalAman bansal
Aman bansal
 
POS 408 Extraordinary Life/newtonhelp.com 
POS 408 Extraordinary Life/newtonhelp.com POS 408 Extraordinary Life/newtonhelp.com 
POS 408 Extraordinary Life/newtonhelp.com 
 
jeetCV India
jeetCV IndiajeetCV India
jeetCV India
 
Top Testing Tips
Top Testing TipsTop Testing Tips
Top Testing Tips
 
Mohab CV e
Mohab CV eMohab CV e
Mohab CV e
 
Vikramjit_Resume
Vikramjit_Resume Vikramjit_Resume
Vikramjit_Resume
 

Similar to Presentation on design pattern software project lll

Legacy is Good
Legacy is GoodLegacy is Good
Legacy is Good
Uberto Barbini
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
Naresh Jain
 
How to code to code less
How to code to code lessHow to code to code less
How to code to code less
Anton Novikau
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
adil raja
 
Book management system
Book management systemBook management system
Book management system
SHARDA SHARAN
 
Microservices Chaos Testing at Jet
Microservices Chaos Testing at JetMicroservices Chaos Testing at Jet
Microservices Chaos Testing at Jet
C4Media
 
Making Steaks from Sacred Cows
Making Steaks from Sacred CowsMaking Steaks from Sacred Cows
Making Steaks from Sacred Cows
Kevlin Henney
 
Framework Design Guidelines For Brussels Users Group
Framework Design Guidelines For Brussels Users GroupFramework Design Guidelines For Brussels Users Group
Framework Design Guidelines For Brussels Users Group
brada
 
How much do we know about Object-Oriented Programming?
How much do we know about Object-Oriented Programming?How much do we know about Object-Oriented Programming?
How much do we know about Object-Oriented Programming?
Sandro Mancuso
 
Dot Net Accenture
Dot Net AccentureDot Net Accenture
Dot Net AccentureSri K
 
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++
ppd1961
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)
Jose Manuel Pereira Garcia
 
PRELIM-Lesson-2.pdf
PRELIM-Lesson-2.pdfPRELIM-Lesson-2.pdf
PRELIM-Lesson-2.pdf
jaymaraltamera
 
Structural pattern 3
Structural pattern 3Structural pattern 3
Structural pattern 3
Naga Muruga
 
Overview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company indiaOverview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company india
Jignesh Aakoliya
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfoliomwillmer
 
Virtual function
Virtual functionVirtual function
Virtual function
sdrhr
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And Refactoring
Naresh Jain
 

Similar to Presentation on design pattern software project lll (20)

Legacy is Good
Legacy is GoodLegacy is Good
Legacy is Good
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
 
How to code to code less
How to code to code lessHow to code to code less
How to code to code less
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Book management system
Book management systemBook management system
Book management system
 
Microservices Chaos Testing at Jet
Microservices Chaos Testing at JetMicroservices Chaos Testing at Jet
Microservices Chaos Testing at Jet
 
Making Steaks from Sacred Cows
Making Steaks from Sacred CowsMaking Steaks from Sacred Cows
Making Steaks from Sacred Cows
 
Framework Design Guidelines For Brussels Users Group
Framework Design Guidelines For Brussels Users GroupFramework Design Guidelines For Brussels Users Group
Framework Design Guidelines For Brussels Users Group
 
How much do we know about Object-Oriented Programming?
How much do we know about Object-Oriented Programming?How much do we know about Object-Oriented Programming?
How much do we know about Object-Oriented Programming?
 
Dot Net Accenture
Dot Net AccentureDot Net Accenture
Dot Net Accenture
 
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)
 
PRELIM-Lesson-2.pdf
PRELIM-Lesson-2.pdfPRELIM-Lesson-2.pdf
PRELIM-Lesson-2.pdf
 
Clean code
Clean codeClean code
Clean code
 
Structural pattern 3
Structural pattern 3Structural pattern 3
Structural pattern 3
 
Overview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company indiaOverview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company india
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
 
Virtual function
Virtual functionVirtual function
Virtual function
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And Refactoring
 

Recently uploaded

SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
Peter Caitens
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Hivelance Technology
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
KrzysztofKkol1
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
varshanayak241
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
NaapbooksPrivateLimi
 

Recently uploaded (20)

SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
 

Presentation on design pattern software project lll

  • 1. Presentation on Design Patterns Team : Boolean Poltergeist
  • 2. What is Design Pattern? A D E S I G N P A T T E R N I S A G E N E R A L R E U S A B L E S O L U T I O N T O A C O M M O N L Y O C C U R R I N G P R O B L E M I N S O F T W A R E D E S I G N .
  • 5. The Mediator defines the interface for communication between objects. This is a behavioural pattern as it defines a manner for controlling communication between classes or entities. The mediator pattern is used to reduce coupling between classes that communicate with each other. Brief Description:
  • 7. Implementation 1. Mediator i)This component defines an interface for communicating with Colleague objects. 2. ConcreteMediator i) This component implements cooperative behavior by coordinating Colleague objects. ii)It knows and maintains its colleagues. 3. Colleague classes i) Each Colleague class knows its Mediator object. ii) Each colleague communicates with its mediator whenever it would have otherwise communicated with another colleague.
  • 8. Code Example public abstract Colleague{ private Mediator mediator; public Colleague(Mediator m) { mediator = m; } Colleage interface public void send(String message) { mediator.send(message, this); } send a message via the mediator //Mediator interface public interface Mediator { public void send(String message, Colleague colleague); } Mediator interface public Mediator getMediator() {return mediator;} public abstract void receive(String message); } get access to the mediator public class ApplicationMediator implements Mediator { private ArrayList<Colleague> colleagues; public ApplicationMediator() { colleagues = new ArrayList<Colleague>(); } public void addColleague(Colleague colleague) { colleagues.add(colleague); } public void send(String message, Colleague originator) { //let all other screens know that this screen has changed for(Colleague colleague: colleagues) { //don't tell ourselves if(colleague != originator) { colleage.receive(message); } } } }
  • 9. Code Example public class HeadDepartment implements Department { public class ConcreteColleague extends Colleague { public void receive(String message) { System.out.println("Colleague Received: " + message); } } public class MobileColleague extends Colleague { public void receive(String message) { System.out.println("Mobile Received: " + message); } } public class Client { public static void main(String[] args) { ApplicationMediator mediator = new ApplicationMediator(); ConcreteColleague desktop = new ConcreteColleague(mediator); ConcreteColleague mobile = new MobileColleague(mediator); mediator.addColleague(desktop); mediator.addColleague(mobile); desktop.send("Hello World"); mobile.send("Hello"); } }
  • 10. PROS AND CONS Its one of the main advantage is that we can replace one object in the implementation with a different other object without affecting the classes and the interfaces. Mediator Design Pattern is very simple to understand and implement in real life examples such as chatRoom, Facebook, Air traffic control, Road traffic control etc. Disadvantage of Mediator pattern is that it centralises the communications between various components and thus the mediator pattern deals complexity of interaction for complexity in the mediator. Because a mediator hides protocols, it can become more and more complex than any individual colleague. This can make the mediator itself a large block that is hard to maintain.
  • 11. Examples where Mediator pattern is used Join Facebook Group Air Traffic Control System
  • 13. Iterator is a behavioral design pattern that lets you traverse elements of a collection without exposing its underlying representation (list, stack, tree, etc.). Brief Description:
  • 14. Declare the iterator interface. Implement concrete iterator classes for the collections that you want to be traversable with iterators. Implement the collection interface in your collection classes. Step 1 Declare the collection interface and describe a method for fetching iterators. Step 2 Step 3 Step 4 Implementation Step 5 Go over the client code to replace all of the collection traversal code with the use of iterators.
  • 16. Code Example public interface Iterator { boolean hasNext(); String Next(); } public interface TV { Iterator getIterator(); } public class ConcreteIterator implements Iterator{ int index=0; @Override public boolean hasNext() { if (index < channels.length) return true; return false; } @Override public String Next() { if(hasNext()) { return channels[index++]; } return null; } public class ConcreteTV implements TV{ private String[] channels = {"NTV", "GTV", "GB"}; private Iterator iterator; public ConcreteTV() { iterator= new ConcreteIterator(); } @Override public Iterator getIterator() { return iterator; } Iterator.java TV.java ConcreteIterator ConcreteTV.java
  • 17. Code Example public class Demo { public static void main(String[] args) { TV tv = new ConcreteTV(); Iterator iterator = tv.getIterator(); while (iterator.hasNext()) { String channel = iterator.Next(); System.out.println("TV is Playing "+channel); } } } Demo.java
  • 18. PROS AND CONS We can iterate over the same collection in parallel because each iterator object contains its own iteration state. Open/Closed Principle. Single Responsibility Principle. Using an iterator may be less efficient than going through elements of some specialized collections directly. Applying the pattern can be an overkill if your app only works with simple collections.
  • 19. Examples where Iterate pattern is used TV Remote A good example of an Iterator is a TV remote, which has the “next” and “previous” buttons to surf TV channels. Media Players In media players, we have a list of songs listed and we can play the song by traversing to the songs list and select desired song. It’s also an iterator example.
  • 21. Bridge is a structural design pattern that lets you split a large class or a set of closely related classes into two separate hierarchies— abstraction and implementation—which can be developed independently of each other. Brief Description:
  • 22. first what operations the client needs and define them in the base abstraction class. Declare the ones that the abstraction needs in the general implementation interface. For all platforms in the domain create concrete implementation classes, but make sure they all follow the implementation interface. Inside the abstraction class, add a reference field for the implementation type. If there have several variants of high-level logic, create refined abstractions for each variant by extending the base abstraction class. The client code should pass an implementation object to the abstraction’s constructor to associate one with the other. Implementation
  • 24. Code Example with any language with Diagram : Color.java public interface Color { String fill(); } Implementcolor.java public class Blue implements Color { @Override public String fill() { return "Color is Blue"; } }
  • 25. Shape.java public abstract class Shape { protected Color color; abstract public String draw(); } extendShape.java public class Square extends Shape { public Square(Color color) { super(color); } @Override public String draw() { return "Square drawn. " + color.fill(); } } test.java @Test public void whenBridgePatternInvoked_thenConfigSuccess() { Shape square = new Square(new Red()); assertEquals(square.draw(), "Square drawn. Color is Red"); } Code Steps :
  • 26. Pros and Cons of the pattern : It can create platform- independent classes and apps. The client code works with high- level abstractions. It isn’t exposed to the platform details. It can introduce new abstractions and implementations independently from each other. Pros : it might make the code more complicated by applying the pattern to a highly cohesive class. Cons :
  • 27. Examples where Iterate pattern is used: For Retail shop owner For software developer If you are a software developer and if you are using some software for writing some data, you could just call an API for doing the job. If you are a retail shop owner and you send a message to the customers regarding the new products whenever they arrive at the shop. So, you need to intimate the customers via SMS. You will use some software for doing that job. You click on send the message with the help of that software.
  • 28. Design Patterns - Decorator Pattern 201-15-3277 By : Ahmed Ishtiak Nihal
  • 29. Decorator is a design pattern that allows you to attach additional behaviors to objects by enclosing them in special wrapper objects that contain the behaviors. Brief Description:
  • 30. IMPLEMANTION WITH (DIAGRAM) Ascertain that your company's domain may be represented as a major component with several optional layers layered on top of it. AAI | Pro X Figure out what methods are common to both the primary component and the optional layers. Create a component interface and declare those methods there. Create a concrete component class in which to define the base behavior. Make a decorator base class. It should provide a field for storing a wrapped object reference. Ascertain that all classes adhere to the component interface. Create concrete decorators by extending them from the base decorator. The client code must be responsible for creating decorators and composing them in the way the client needs.
  • 31. W E ' L L M A K E A S H A P E I N T E R F A C E A S W E L L A S C O N C R E T E C L A S S E S T H A T I M P L E M E N T T H E S H A P E I N T E R F A C E . A F T E R T H A T , W E ' L L M A K E A N A B S T R A C T D E C O R A T O R C L A S S C A L L E D S H A P E D E C O R A T O R T H A T I M P L E M E N T S T H E S H A P E I N T E R F A C E A N D H A S A S H A P E O B J E C T A S A N I N S T A N C E V A R I A B L E . R E D S H A P E D E C O R A T O R I S A C O N C R E T E C L A S S I M P L E M E N T I N G S H A P E D E C O R A T O R . D E C O R A T O R P A T T E R N D E M O , O U R D E M O C L A S S W I L L U S E R E D S H A P E D E C O R A T O R T O D E C O R A T E S H A P E O B J E C T S . CODE EXAMPLE WITH DIAGRAM
  • 32. Shape.java public interface Shape { void draw(); } Step 1 Step 2 Rectangle.java public class Rectangle implements Shape { @Override public void draw() { System.out.println("Shape: Rectangle"); } } Step 2 Circle.java public class Circle implements Shape { @Override public void draw() { System.out.println("Shape: Circle"); } } Step 3 ShapeDecorator.java public abstract class ShapeDecorator implements Shape { protected Shape decoratedShape; public ShapeDecorator(Shape decoratedShape){ this.decoratedShape = decoratedShape; } public void draw(){ decoratedShape.draw(); } }
  • 33. Step 4 RedShapeDecorator.java public class RedShapeDecorator extends ShapeDecorator { public RedShapeDecorator(Shape decoratedShape) { super(decoratedShape); } @Override public void draw() { decoratedShape.draw(); setRedBorder(decoratedShape); } private void setRedBorder(Shape decoratedShape){ System.out.println("Border Color: Red"); } } Step 5 DecoratorPatternDemo.java public class DecoratorPatternDemo { public static void main(String[] args) { Shape circle = new Circle(); Shape redCircle = new RedShapeDecorator(new Circle()); Shape redRectangle = new RedShapeDecorator(new Rectangle()); System.out.println("Circle with normal border"); circle.draw(); System.out.println("nCircle of red border"); redCircle.draw(); System.out.println("nRectangle of red border"); redRectangle.draw(); } }
  • 34. PROS AND CONS You can change the behavior of an object without creating a new subclass. At runtime, you can add or remove responsibilities from an object. Wrapping an object in numerous decorators allows you to mix multiple behaviors. Principle of a single point of responsibility. A monolithic class that implements several possible behavior variants can be broken down into several smaller classes. Pros : It's difficult to remove a specific wrapper from the stack of wrappers. It's difficult to create a decorator whose behavior is independent of the sequence in which the decorators are stacked. The initial configuration code of layers might look pretty ugly. Cons :
  • 35. A N A S S A U L T G U N I S A D E A D L Y W E A P O N O N I T S O W N . B U T Y O U C A N A P P L Y C E R T A I N " D E C O R A T I O N S " T O M A K E I T M O R E A C C U R A T E , S I L E N T A N D D E V A S T A T I N G . T H E D E C O R A T O R A T T A C H E S A D D I T I O N A L R E S P O N S I B I L I T I E S T O A N O B J E C T D Y N A M I C A L L Y . T H E O R N A M E N T S T H A T A R E A D D E D T O P I N E O R F I R T R E E S A R E E X A M P L E S O F D E C O R A T O R S . L I G H T S , G A R L A N D , C A N D Y C A N E S , G L A S S O R N A M E N T S , E T C . , C A N B E A D D E D T O A T R E E T O G I V E I T A F E S T I V E L O O K . T H E O R N A M E N T S D O N O T C H A N G E T H E T R E E I T S E L F W H I C H I S R E C O G N I Z A B L E A S A C H R I S T M A S T R E E R E G A R D L E S S O F P A R T I C U L A R O R N A M E N T S U S E D . A S A N E X A M P L E O F A D D I T I O N A L F U N C T I O N A L I T Y , T H E A D D I T I O N O F L I G H T S A L L O W S O N E T O " L I G H T U P " A C H R I S T M A S T R E E . Examples where Decorator pattern is used
  • 37. Composite is a structural design pattern that lets you compose objects into tree structures and then work with these structures as if they were individual objects. Brief Description:
  • 38. Create a leaf class to represent simple elements. A program may have multiple different leaf classes. Create a container class to represent complex elements. In this class, provide an array field for storing references to sub-elements. Step 1 Make sure that the core model of your app can be represented as a tree structure. Step 2 Step 3 Step 4 Implementation Step 5 Finally, define the methods for adding and removal of child elements in the container. Implement concrete iterator classes for the collections that you want to be traversable with iterators.
  • 40. Code Example public class FinancialDepartment implements Department { private Integer id; private String name; public void printDepartmentName() { System.out.println(getid().getSimpleName()); } // standard constructor, getters, setters } public interface Department { void printDepartmentName(); } Department FinancialDepartment public class SalesDepartment implements Department { private Integer id; private String name; public void printDepartmentName() { System.out.println(getid().getSimpleName()); } // standard constructor, getters, setters } SalesDepartment
  • 41. Code Example public class HeadDepartment implements Department { private Integer id; private String name; private List<Department> childDepartments; public HeadDepartment(Integer id, String name) { this.id = id; this.name = name; this.childDepartments = new ArrayList<>(); } public void printDepartmentName() { childDepartments.forEach(Department::printDepartmentName); } public void addDepartment(Department department) { childDepartments.add(department); } public void removeDepartment(Department department) { childDepartments.remove(department); } } public class CompositeDemo { public static void main(String args[]) { Department salesDepartment = new SalesDepartment( 1, "Sales department"); Department financialDepartment = new FinancialDepartment( 2, "Financial department"); HeadDepartment headDepartment = new HeadDepartment( 3, "Head department"); headDepartment.addDepartment(salesDepartment); headDepartment.addDepartment(financialDepartment); headDepartment.printDepartmentName(); } } } HeadDepartment CompositeDemo
  • 42. PROS AND CONS Open/Closed Principle. You can introduce new element types into the app without breaking the existing code, which now works with the object tree. You can work with complex tree structures more conveniently: use polymorphism and recursion to your advantage. It might be difficult to provide a common interface for classes whose functionality differs too much. In certain scenarios, you’d need to overgeneralize the component interface, making it harder to comprehend.
  • 43. Examples where Iterate pattern is used Directory structure in file system implementations Group messaging
  • 45. The Template Method pattern provides a method in a super-class, usually an abstract super-class, and defines the skeleton of an operation in terms of several high-level steps. Generally, these steps are implemented by additional helper methods in the same class as the template method. Brief Description:
  • 46. Implementation : We are going to create a Game abstract class defining operations with a template method set to be final so that it cannot be overridden. Cricket and Football are concrete classes that extend Game and override its methods. TemplatePatternDemo, our demo class, will use Game to demonstrate use of template pattern.
  • 48. Code : Step 1 Create an abstract class with a template method being final. Game.java public abstract class Game { abstract void initialize(); abstract void startPlay(); abstract void endPlay(); //template method public final void play(){ //initialize the game initialize(); //start game startPlay(); //end game endPlay(); } }
  • 49. Step 2 Create concrete classes extending the above class. Cricket.java public class Cricket extends Game { @Override void endPlay() { System.out.println("Cricket Game Finished!"); } @Override void initialize() { System.out.println("Cricket Game Initialized! Start playing."); } @Override void startPlay() { System.out.println("Cricket Game Started. Enjoy the game!"); } } Football.java public class Football extends Game { @Override void endPlay() { System.out.println("Football Game Finished!"); } @Override void initialize() { System.out.println("Football Game Initialized! Start playing."); } @Override void startPlay() { System.out.println("Football Game Started. Enjoy the game!"); } }
  • 50. Step 3 Use the Game's template method play() to demonstrate a defined way of playing game. TemplatePatternDemo.java public class TemplatePatternDemo { public static void main(String[] args) { Game game = new Cricket(); game.play(); System.out.println(); game = new Football(); game.play(); } }
  • 51. Step 4 Verify the output. Cricket Game Initialized! Start playing. Cricket Game Started. Enjoy the game! Cricket Game Finished! Football Game Initialized! Start playing. Football Game Started. Enjoy the game! Football Game Finished!
  • 52. PROS AND CONS Pros: 1. Easy to Implement and readable 2. Flexible. 3. Clear Architecture Cons: 1. Enforce a particular Design 2. Maintenance Issue
  • 53. 1. Daily Routine of a Worker Example 2. Prepared Coffee
  • 54. Nur-A-Alam Siddiqi ID: 201-15-3274 Sheikh Fahim Karzon ID: 201-15-3459 Singleton Pattern
  • 55. Singleton pattern is one of the simpleest design patterns in java. This type of design pattern comes under creational pattern as the pattern provides one of the best ways to creat an object Brief Description:
  • 60. Pros and coins You can be sure that a class has only a single instance. You gain a global access point to that instance. The singleton object is initialized only when it’s requested for the first time. Violates the Single Responsibility Principle. The pattern solves two problems at the time. The Singleton pattern can mask bad design, for instance, when the components of the program know too much about each other. The pattern requires special treatment in a multithreaded environment so that multiple threads won’t create a singleton object several times.
  • 61. Singleton pattern used It is used where only a single instance of a class is required to control the action throughout the execution Singleton Pattern Used in Java Stand Library 1. Singleton Pattern Used in driver objects 2.
  • 62. Md. Shahin Alam ID:201-15-3186 Ahmed Ishtiak Nihal ID:201-15-3277 Yousuf Rayhan Emom ID:201-15-3220 MD Saimur Rahman Swarnab ID:201-15-3303 Team member
  • 63. Md. Sakibuzzzman Alif ID:201-15-3339 Nahidul Islam ID:201-15-3153 Sheikh Fahim Karzon ID:201-15-3459 Nur -A- Alom siddiqi ID:201-15-3274 Team member