SlideShare a Scribd company logo
OBJECT ORIENTED PROGRAMMING
MODULE- 3
DESIGN PATTERNS IN JAVA
DESIGN PATTERNS IN JAVA
 A design patterns are well-proved solution for solving the specific
problem/task.
 Design patterns represent the best practices used by experienced object-
oriented software developers. Design patterns are solutions to general
problems that software developers faced during software development. These
solutions were obtained by trial and error by numerous software developers
over quite a substantial period of time.
 A design pattern systematically names, motivates, and explains a general
design that addresses a recurring design problem in object-oriented systems.
It describes the problem, the solution, when to apply the solution, and its
consequences. It also gives implementation hints and examples.

WHAT IS GANG OF FOUR (GOF)?
 In 1994, four authors Erich Gamma, Richard Helm, Ralph
Johnson and John Vlissides published a book titled Design
Patterns - Elements of Reusable Object-Oriented
Software which initiated the concept of Design Pattern in
Software development.
 These authors are collectively known as Gang of Four
(GOF).
 According to these authors design patterns are primarily
based on the following principles of object orientated design.
Program to an interface not an implementation
Favor object composition over inheritance
USAGE OF DESIGN PATTERN
 Design Patterns have two main usages in software development.
 Common platform for developers
Design patterns provide a standard terminology and are specific to particular scenario. For
example, a singleton design pattern signifies use of single object so all developers familiar
with single design pattern will make use of single object and they can tell each other that
program is following a singleton pattern.
 Best Practices
Design patterns have been evolved over a long period of time and they provide best solutions
to certain problems faced during software development. Learning these patterns helps
unexperienced developers to learn software design in an easy and faster way.
WHAT ARE DESIGN PATTERNS IN JAVA?
 Design Patterns in Java are very talked-about among
software system developers. A design pattern could be a
well-described answer to a typical software system problem.
Some of the advantages of using design patterns are:
 Java Design Patterns provide a traditional business approach
to resolve a recurring problem. Therefore it saves time if we
use the design pattern. There are several Java design
patterns that we can use in our Java projects.
 Using design patterns in Java promotes reusability that ends
up in a lot of robust and highly maintainable code. It helps in
reducing Total Cost of Ownership (TCO) of the software
package.
 Since design patterns are already defined, it makes our code
straightforward to understand and debug. It ends up in
quicker development and new members of the team are
aware of it simply
ADVANTAGE OF DESIGN PATTERN:
 They are reusable in multiple projects.
 They provide the solutions that help to define the system architecture.
 They capture the software engineering experiences.
 They provide transparency to the design of an application.
 They are well-proved and testified solutions since they have been built
upon the knowledge and experience of expert software developers.
 Design patterns don’t guarantee an absolute solution to a problem. They
provide clarity to the system architecture and the possibility of building a
better system.
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 are already defined and provides industry standard
approach to solve a recurring problem, so it saves time if we sensibly
use the design pattern. There are many java design patterns that we can
use in our java based projects.
 Using design patterns promotes reusability that leads to
more robust and highly maintainable code. It helps in reducing total cost
of ownership (TCO) of the software product.
 Since design patterns are already defined, it makes our code easy to
understand and debug. It leads to faster development and new members
of team understand it easily.
TYPES OF DESIGN PATTERNS
TYPES OF DESIGN PATTERNS IN JAVA
These Java design patterns have 3 categories – Creational, Structural, and
Behavioural design patterns.
a) Creational Design Patterns in Java
 Creational design patterns in Java give an answer to instantiate an object within
the very best approach for specific things.
 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 (i.e. creating an object of a class).
 Creational patterns often used in place of direct instantiation with constructors.
They make the creation process more adaptable and dynamic.
 In particular, they can provide a great deal of flexibility about which objects are
created, how those objects are created, and how they are initialized.
 These design patterns provide a way to create objects while hiding the creation
logic, rather than instantiating objects directly using new operator. This gives
program more flexibility in deciding which objects need to be created for a given
use case.
TYPES OF DESIGN PATTERNS IN JAVA CONTD.
i. Singleton Pattern
Singleton design patterns in Java restricts the instantiation of a class and ensures that just one
instance of the class exists within the Java virtual machine. It looks to be a really easy design
pattern, however, once it involves implementation, it comes with a lot of implementation
concerns. The implementation of the Singleton pattern has always been a disputable topic
among developers.
 Singleton Pattern says that just "define a class that has only one instance and
provides a global point of access to it".
 In other words, a class must ensure that only single instance should be created and
single object can be used by all other classes.
 There are two forms of singleton design pattern
 Early Instantiation: creation of instance at load time.
 Lazy Instantiation: creation of instance when required.
TYPES OF DESIGN PATTERNS IN JAVA CONTD.
(ii) Factory Method Pattern
A Factory Pattern or Factory Method Pattern says that just define an interface or abstract
class for creating an object but let the subclasses decide which class to
instantiate. In other words, subclasses are responsible to create the instance of the class.
 The Factory Method Pattern is also known as Virtual Constructor.
 Factory design pattern is most suitable when complex object creation steps are involved.
To ensure that these steps are centralized and not exposed to composing classes.
 Factory design pattern is used when we have a super class with multiple sub-classes and
based on input, we need to return one of the sub-class. This pattern take out the
responsibility of instantiation of a class from client program to the factory class.
 Factory design patterns in Java is used once we have an excellent class with multiple
sub-classes and a super input. In this, we need to define the interface or abstract class
for creating an object. Subclasses are responsible for the creation of an instance of the
class.
TYPES OF DESIGN PATTERNS IN JAVA CONTD.
(iii.) Abstract Factory Pattern
 Abstract factory Java pattern can compare to factory pattern and its
factory of factories. A single factory category that returns the various
sub-classes supported the input provided and factory class uses if-else
or switch statement to attain this. An Abstract Factory Pattern is also
known as Kit.
 In Abstract factory pattern, we tend to eliminate if-else block and have a
factory class for every sub-class and so an Abstract factory class which
will return the sub-class supported the input factory category.
 Abstract Factory Pattern says that just define an interface or abstract
class for creating families of related (or dependent) objects but
without specifying their concrete sub-classes. That means Abstract
Factory lets a class returns a factory of classes. So, this is the reason
that Abstract Factory Pattern is one level higher than the Factory
Pattern.
B) STRUCTURAL DESIGN PATTERNS IN JAVA
 Structural Java patterns give alternative ways to form a class
structure, as an example mistreatment inheritance and
composition to form an outsized object from small objects.
 Structural design patterns are concerned with how classes
and objects can be composed, to form larger structures.
 The structural design patterns simplifies the structure by
identifying the relationships.
 These patterns focus on, how the classes inherit from each
other and how they are composed from other classes.
STRUCTURAL DESIGN PATTERNS IN JAVA CONTD.
 (i) Flyweight Pattern
 Flyweight design pattern is used when we need to create a lot of Objects of a class. Since every
object consumes memory space that can be crucial for low memory devices, such as mobile
devices or embedded systems, flyweight design pattern can be applied to reduce the load on
memory by sharing objects. String Pool implementation in java is one of the best example of
Flyweight pattern implementation.
(ii) Bridge Pattern
 When we have interface hierarchies in both interfaces as well as implementations, then bridge
design pattern is used to decouple the interfaces from implementation and hiding the
implementation details from the client programs. Like Adapter pattern, it’s one of the Structural
design pattern.
 The implementation of bridge design pattern follows the notion to prefer Composition over
inheritance.
 Bridge design pattern is used to decouple a class into two parts – abstraction and
it’s implementation – so that both can evolve in future without affecting each other. It increases the
loose coupling between class abstraction and it’s implementation.
 A Bridge Pattern says that just "decouple the functional abstraction from the implementation
so that the two can vary independently".
 The Bridge Pattern is also known as Handle or Body.
C) BEHAVIORAL DESIGN PATTERNS
These design patterns are specifically concerned with communication
between objects.
Behavioral design patterns are concerned with the interaction and
responsibility of objects.
In these design patterns, the interaction between the objects should be
in such a way that they can easily talk to each other and still should
be loosely coupled.
That means the implementation and the client should be loosely coupled in
order to avoid hard coding and dependencies.
(I) OBSERVER PATTERN
 Observer pattern defines a one-to-many dependency
between objects so that when one object changes
state, all its dependents are notified and updated
automatically.
 It is also referred to as the publish-subscribe pattern.
(ii) Iterator
 According to GoF, Iterator Pattern is used "to access the
elements of an aggregate object sequentially without
exposing its underlying implementation".
 The Iterator pattern is also known as Cursor.
 In collection framework, we are now using Iterator that is
preferred over Enumeration.
 Iterator pattern provides a way to access the elements of
an aggregate object sequentially without exposing its
underlying representation.

More Related Content

What's hot

Reoprt on indutrial training
Reoprt on indutrial trainingReoprt on indutrial training
Reoprt on indutrial training
PratikKhodwe1
 
Learning uml 2_part_1
Learning uml 2_part_1Learning uml 2_part_1
Learning uml 2_part_1
Mark Gaad
 
Design patterns through refactoring
Design patterns through refactoringDesign patterns through refactoring
Design patterns through refactoring
Ganesh Samarthyam
 
Code Craftsmanship Checklist
Code Craftsmanship ChecklistCode Craftsmanship Checklist
Code Craftsmanship Checklist
Ryan Polk
 
Introduction to Design Patterns
Introduction to Design PatternsIntroduction to Design Patterns
Introduction to Design Patterns
Joao Pereira
 
3. C# Guide Advance - To Print
3. C# Guide Advance - To Print3. C# Guide Advance - To Print
3. C# Guide Advance - To PrintChinthaka Fernando
 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented Programming
Anumod Kumar
 
Modelling the User Interface
Modelling the User InterfaceModelling the User Interface
Modelling the User Interface
Pedro J. Molina
 
Industrial and Academic Experiences with a User Interaction Modeling Language...
Industrial and Academic Experiences with a User Interaction Modeling Language...Industrial and Academic Experiences with a User Interaction Modeling Language...
Industrial and Academic Experiences with a User Interaction Modeling Language...
Marco Brambilla
 
Architecting Drupal Modules - Report from the frontlines
Architecting Drupal Modules - Report from the frontlinesArchitecting Drupal Modules - Report from the frontlines
Architecting Drupal Modules - Report from the frontlines
Ronald Ashri
 
Architecture: where do you start?
 Architecture: where do you start? Architecture: where do you start?
Architecture: where do you start?
Skills Matter
 
Java session01
Java session01Java session01
Java session01Niit Care
 
Refactoring for Design Smells - ICSE 2014 Tutorial
Refactoring for Design Smells - ICSE 2014 TutorialRefactoring for Design Smells - ICSE 2014 Tutorial
Refactoring for Design Smells - ICSE 2014 Tutorial
Tushar Sharma
 
Java Technicalities
Java TechnicalitiesJava Technicalities
Java Technicalities
Wen-Shih Chao
 
Software Architecture: Principles, Patterns and Practices
Software Architecture: Principles, Patterns and PracticesSoftware Architecture: Principles, Patterns and Practices
Software Architecture: Principles, Patterns and Practices
Ganesh Samarthyam
 
Refactoring for Software Design Smells
Refactoring for Software Design SmellsRefactoring for Software Design Smells
Refactoring for Software Design Smells
Ganesh Samarthyam
 
01 iec t1_s1_oo_ps_session_01
01 iec t1_s1_oo_ps_session_0101 iec t1_s1_oo_ps_session_01
01 iec t1_s1_oo_ps_session_01Niit Care
 

What's hot (20)

Reoprt on indutrial training
Reoprt on indutrial trainingReoprt on indutrial training
Reoprt on indutrial training
 
Learning uml 2_part_1
Learning uml 2_part_1Learning uml 2_part_1
Learning uml 2_part_1
 
Design patterns through refactoring
Design patterns through refactoringDesign patterns through refactoring
Design patterns through refactoring
 
Code Craftsmanship Checklist
Code Craftsmanship ChecklistCode Craftsmanship Checklist
Code Craftsmanship Checklist
 
Introduction to Design Patterns
Introduction to Design PatternsIntroduction to Design Patterns
Introduction to Design Patterns
 
Advance Java - 2nd Unit
Advance Java - 2nd UnitAdvance Java - 2nd Unit
Advance Java - 2nd Unit
 
3. C# Guide Advance - To Print
3. C# Guide Advance - To Print3. C# Guide Advance - To Print
3. C# Guide Advance - To Print
 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented Programming
 
Modelling the User Interface
Modelling the User InterfaceModelling the User Interface
Modelling the User Interface
 
Acceleo Code Generation
Acceleo Code GenerationAcceleo Code Generation
Acceleo Code Generation
 
6
66
6
 
Industrial and Academic Experiences with a User Interaction Modeling Language...
Industrial and Academic Experiences with a User Interaction Modeling Language...Industrial and Academic Experiences with a User Interaction Modeling Language...
Industrial and Academic Experiences with a User Interaction Modeling Language...
 
Architecting Drupal Modules - Report from the frontlines
Architecting Drupal Modules - Report from the frontlinesArchitecting Drupal Modules - Report from the frontlines
Architecting Drupal Modules - Report from the frontlines
 
Architecture: where do you start?
 Architecture: where do you start? Architecture: where do you start?
Architecture: where do you start?
 
Java session01
Java session01Java session01
Java session01
 
Refactoring for Design Smells - ICSE 2014 Tutorial
Refactoring for Design Smells - ICSE 2014 TutorialRefactoring for Design Smells - ICSE 2014 Tutorial
Refactoring for Design Smells - ICSE 2014 Tutorial
 
Java Technicalities
Java TechnicalitiesJava Technicalities
Java Technicalities
 
Software Architecture: Principles, Patterns and Practices
Software Architecture: Principles, Patterns and PracticesSoftware Architecture: Principles, Patterns and Practices
Software Architecture: Principles, Patterns and Practices
 
Refactoring for Software Design Smells
Refactoring for Software Design SmellsRefactoring for Software Design Smells
Refactoring for Software Design Smells
 
01 iec t1_s1_oo_ps_session_01
01 iec t1_s1_oo_ps_session_0101 iec t1_s1_oo_ps_session_01
01 iec t1_s1_oo_ps_session_01
 

Similar to Oops design pattern intro

Design patterns
Design patternsDesign patterns
Design patterns
Kolade Ibrahim Arowolo
 
Why Design Patterns Are Important In Software Engineering
Why Design Patterns Are Important In Software EngineeringWhy Design Patterns Are Important In Software Engineering
Why Design Patterns Are Important In Software Engineering
Protelo, Inc.
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Luis Valencia
 
Design patterns
Design patternsDesign patterns
Design patterns
Akhilesh Joshi
 
Software design and Architecture.pptx
Software design and Architecture.pptxSoftware design and Architecture.pptx
Software design and Architecture.pptx
SHAHZAIBABBAS13
 
Module 2 design patterns-2
Module 2   design patterns-2Module 2   design patterns-2
Module 2 design patterns-2
Ankit Dubey
 
Introduction To Design Patterns
Introduction To Design PatternsIntroduction To Design Patterns
Introduction To Design Patterns
sukumarraju6
 
Design pattern
Design patternDesign pattern
Design pattern
Ramakrishna kapa
 
Unit No 6 Design Patterns.pptx
Unit No 6 Design Patterns.pptxUnit No 6 Design Patterns.pptx
Unit No 6 Design Patterns.pptx
DrYogeshDeshmukh1
 
Practical OOP In Java
Practical OOP In JavaPractical OOP In Java
Practical OOP In Java
wiradikusuma
 
Object-Oriented Programming in Java.pdf
Object-Oriented Programming in Java.pdfObject-Oriented Programming in Java.pdf
Object-Oriented Programming in Java.pdf
Bharath Choudhary
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
Mindfire Solutions
 
Design pattern in an expressive language java script
Design pattern in an expressive language java scriptDesign pattern in an expressive language java script
Design pattern in an expressive language java scriptAmit Thakkar
 
Design Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldDesign Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The World
Saurabh Moody
 
Dynamic component composition
Dynamic component compositionDynamic component composition
Dynamic component composition
ijseajournal
 
Ujjwalreverseengineeringppptfinal
UjjwalreverseengineeringppptfinalUjjwalreverseengineeringppptfinal
Ujjwalreverseengineeringppptfinalujjwalchauhan87
 
Design patterns
Design patternsDesign patterns
Design patterns
Binu Bhasuran
 
Design pattern
Design patternDesign pattern
Design pattern
Shreyance Jain
 

Similar to Oops design pattern intro (20)

Design patterns
Design patternsDesign patterns
Design patterns
 
Why Design Patterns Are Important In Software Engineering
Why Design Patterns Are Important In Software EngineeringWhy Design Patterns Are Important In Software Engineering
Why Design Patterns Are Important In Software Engineering
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Software design and Architecture.pptx
Software design and Architecture.pptxSoftware design and Architecture.pptx
Software design and Architecture.pptx
 
Module 2 design patterns-2
Module 2   design patterns-2Module 2   design patterns-2
Module 2 design patterns-2
 
Introduction To Design Patterns
Introduction To Design PatternsIntroduction To Design Patterns
Introduction To Design Patterns
 
Design pattern
Design patternDesign pattern
Design pattern
 
Unit No 6 Design Patterns.pptx
Unit No 6 Design Patterns.pptxUnit No 6 Design Patterns.pptx
Unit No 6 Design Patterns.pptx
 
Practical OOP In Java
Practical OOP In JavaPractical OOP In Java
Practical OOP In Java
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Object-Oriented Programming in Java.pdf
Object-Oriented Programming in Java.pdfObject-Oriented Programming in Java.pdf
Object-Oriented Programming in Java.pdf
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
 
Dtacs
DtacsDtacs
Dtacs
 
Design pattern in an expressive language java script
Design pattern in an expressive language java scriptDesign pattern in an expressive language java script
Design pattern in an expressive language java script
 
Design Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldDesign Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The World
 
Dynamic component composition
Dynamic component compositionDynamic component composition
Dynamic component composition
 
Ujjwalreverseengineeringppptfinal
UjjwalreverseengineeringppptfinalUjjwalreverseengineeringppptfinal
Ujjwalreverseengineeringppptfinal
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Design pattern
Design patternDesign pattern
Design pattern
 

More from anshu_atri

Types of input and output devices
Types of input and output devicesTypes of input and output devices
Types of input and output devices
anshu_atri
 
Types of computers
Types of computersTypes of computers
Types of computers
anshu_atri
 
Intro of computers
Intro of computersIntro of computers
Intro of computers
anshu_atri
 
Observer pattern
Observer patternObserver pattern
Observer pattern
anshu_atri
 
Examination process (1)
Examination process (1)Examination process (1)
Examination process (1)
anshu_atri
 
Iterator pattern
Iterator patternIterator pattern
Iterator pattern
anshu_atri
 
Singleton design pattern
Singleton design patternSingleton design pattern
Singleton design pattern
anshu_atri
 
Generic programming in java
Generic programming in javaGeneric programming in java
Generic programming in java
anshu_atri
 
Acem web designing
Acem web designingAcem web designing
Acem web designing
anshu_atri
 
Super and final in java
Super and final in javaSuper and final in java
Super and final in java
anshu_atri
 
Aravali college of engg. and management
Aravali college of engg. and managementAravali college of engg. and management
Aravali college of engg. and management
anshu_atri
 

More from anshu_atri (11)

Types of input and output devices
Types of input and output devicesTypes of input and output devices
Types of input and output devices
 
Types of computers
Types of computersTypes of computers
Types of computers
 
Intro of computers
Intro of computersIntro of computers
Intro of computers
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Examination process (1)
Examination process (1)Examination process (1)
Examination process (1)
 
Iterator pattern
Iterator patternIterator pattern
Iterator pattern
 
Singleton design pattern
Singleton design patternSingleton design pattern
Singleton design pattern
 
Generic programming in java
Generic programming in javaGeneric programming in java
Generic programming in java
 
Acem web designing
Acem web designingAcem web designing
Acem web designing
 
Super and final in java
Super and final in javaSuper and final in java
Super and final in java
 
Aravali college of engg. and management
Aravali college of engg. and managementAravali college of engg. and management
Aravali college of engg. and management
 

Recently uploaded

Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 

Recently uploaded (20)

Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 

Oops design pattern intro

  • 1. OBJECT ORIENTED PROGRAMMING MODULE- 3 DESIGN PATTERNS IN JAVA
  • 2. DESIGN PATTERNS IN JAVA  A design patterns are well-proved solution for solving the specific problem/task.  Design patterns represent the best practices used by experienced object- oriented software developers. Design patterns are solutions to general problems that software developers faced during software development. These solutions were obtained by trial and error by numerous software developers over quite a substantial period of time.  A design pattern systematically names, motivates, and explains a general design that addresses a recurring design problem in object-oriented systems. It describes the problem, the solution, when to apply the solution, and its consequences. It also gives implementation hints and examples. 
  • 3. WHAT IS GANG OF FOUR (GOF)?  In 1994, four authors Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides published a book titled Design Patterns - Elements of Reusable Object-Oriented Software which initiated the concept of Design Pattern in Software development.  These authors are collectively known as Gang of Four (GOF).  According to these authors design patterns are primarily based on the following principles of object orientated design. Program to an interface not an implementation Favor object composition over inheritance
  • 4. USAGE OF DESIGN PATTERN  Design Patterns have two main usages in software development.  Common platform for developers Design patterns provide a standard terminology and are specific to particular scenario. For example, a singleton design pattern signifies use of single object so all developers familiar with single design pattern will make use of single object and they can tell each other that program is following a singleton pattern.  Best Practices Design patterns have been evolved over a long period of time and they provide best solutions to certain problems faced during software development. Learning these patterns helps unexperienced developers to learn software design in an easy and faster way.
  • 5. WHAT ARE DESIGN PATTERNS IN JAVA?  Design Patterns in Java are very talked-about among software system developers. A design pattern could be a well-described answer to a typical software system problem. Some of the advantages of using design patterns are:  Java Design Patterns provide a traditional business approach to resolve a recurring problem. Therefore it saves time if we use the design pattern. There are several Java design patterns that we can use in our Java projects.
  • 6.  Using design patterns in Java promotes reusability that ends up in a lot of robust and highly maintainable code. It helps in reducing Total Cost of Ownership (TCO) of the software package.  Since design patterns are already defined, it makes our code straightforward to understand and debug. It ends up in quicker development and new members of the team are aware of it simply
  • 7. ADVANTAGE OF DESIGN PATTERN:  They are reusable in multiple projects.  They provide the solutions that help to define the system architecture.  They capture the software engineering experiences.  They provide transparency to the design of an application.  They are well-proved and testified solutions since they have been built upon the knowledge and experience of expert software developers.  Design patterns don’t guarantee an absolute solution to a problem. They provide clarity to the system architecture and the possibility of building a better system.
  • 8. 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 are already defined and provides industry standard approach to solve a recurring problem, so it saves time if we sensibly use the design pattern. There are many java design patterns that we can use in our java based projects.  Using design patterns promotes reusability that leads to more robust and highly maintainable code. It helps in reducing total cost of ownership (TCO) of the software product.  Since design patterns are already defined, it makes our code easy to understand and debug. It leads to faster development and new members of team understand it easily.
  • 9. TYPES OF DESIGN PATTERNS
  • 10. TYPES OF DESIGN PATTERNS IN JAVA These Java design patterns have 3 categories – Creational, Structural, and Behavioural design patterns. a) Creational Design Patterns in Java  Creational design patterns in Java give an answer to instantiate an object within the very best approach for specific things.  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 (i.e. creating an object of a class).  Creational patterns often used in place of direct instantiation with constructors. They make the creation process more adaptable and dynamic.  In particular, they can provide a great deal of flexibility about which objects are created, how those objects are created, and how they are initialized.  These design patterns provide a way to create objects while hiding the creation logic, rather than instantiating objects directly using new operator. This gives program more flexibility in deciding which objects need to be created for a given use case.
  • 11. TYPES OF DESIGN PATTERNS IN JAVA CONTD. i. Singleton Pattern Singleton design patterns in Java restricts the instantiation of a class and ensures that just one instance of the class exists within the Java virtual machine. It looks to be a really easy design pattern, however, once it involves implementation, it comes with a lot of implementation concerns. The implementation of the Singleton pattern has always been a disputable topic among developers.  Singleton Pattern says that just "define a class that has only one instance and provides a global point of access to it".  In other words, a class must ensure that only single instance should be created and single object can be used by all other classes.  There are two forms of singleton design pattern  Early Instantiation: creation of instance at load time.  Lazy Instantiation: creation of instance when required.
  • 12. TYPES OF DESIGN PATTERNS IN JAVA CONTD. (ii) Factory Method Pattern A Factory Pattern or Factory Method Pattern says that just define an interface or abstract class for creating an object but let the subclasses decide which class to instantiate. In other words, subclasses are responsible to create the instance of the class.  The Factory Method Pattern is also known as Virtual Constructor.  Factory design pattern is most suitable when complex object creation steps are involved. To ensure that these steps are centralized and not exposed to composing classes.  Factory design pattern is used when we have a super class with multiple sub-classes and based on input, we need to return one of the sub-class. This pattern take out the responsibility of instantiation of a class from client program to the factory class.  Factory design patterns in Java is used once we have an excellent class with multiple sub-classes and a super input. In this, we need to define the interface or abstract class for creating an object. Subclasses are responsible for the creation of an instance of the class.
  • 13. TYPES OF DESIGN PATTERNS IN JAVA CONTD. (iii.) Abstract Factory Pattern  Abstract factory Java pattern can compare to factory pattern and its factory of factories. A single factory category that returns the various sub-classes supported the input provided and factory class uses if-else or switch statement to attain this. An Abstract Factory Pattern is also known as Kit.  In Abstract factory pattern, we tend to eliminate if-else block and have a factory class for every sub-class and so an Abstract factory class which will return the sub-class supported the input factory category.  Abstract Factory Pattern says that just define an interface or abstract class for creating families of related (or dependent) objects but without specifying their concrete sub-classes. That means Abstract Factory lets a class returns a factory of classes. So, this is the reason that Abstract Factory Pattern is one level higher than the Factory Pattern.
  • 14. B) STRUCTURAL DESIGN PATTERNS IN JAVA  Structural Java patterns give alternative ways to form a class structure, as an example mistreatment inheritance and composition to form an outsized object from small objects.  Structural design patterns are concerned with how classes and objects can be composed, to form larger structures.  The structural design patterns simplifies the structure by identifying the relationships.  These patterns focus on, how the classes inherit from each other and how they are composed from other classes.
  • 15. STRUCTURAL DESIGN PATTERNS IN JAVA CONTD.  (i) Flyweight Pattern  Flyweight design pattern is used when we need to create a lot of Objects of a class. Since every object consumes memory space that can be crucial for low memory devices, such as mobile devices or embedded systems, flyweight design pattern can be applied to reduce the load on memory by sharing objects. String Pool implementation in java is one of the best example of Flyweight pattern implementation. (ii) Bridge Pattern  When we have interface hierarchies in both interfaces as well as implementations, then bridge design pattern is used to decouple the interfaces from implementation and hiding the implementation details from the client programs. Like Adapter pattern, it’s one of the Structural design pattern.  The implementation of bridge design pattern follows the notion to prefer Composition over inheritance.  Bridge design pattern is used to decouple a class into two parts – abstraction and it’s implementation – so that both can evolve in future without affecting each other. It increases the loose coupling between class abstraction and it’s implementation.  A Bridge Pattern says that just "decouple the functional abstraction from the implementation so that the two can vary independently".  The Bridge Pattern is also known as Handle or Body.
  • 16. C) BEHAVIORAL DESIGN PATTERNS These design patterns are specifically concerned with communication between objects. Behavioral design patterns are concerned with the interaction and responsibility of objects. In these design patterns, the interaction between the objects should be in such a way that they can easily talk to each other and still should be loosely coupled. That means the implementation and the client should be loosely coupled in order to avoid hard coding and dependencies.
  • 17. (I) OBSERVER PATTERN  Observer pattern defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.  It is also referred to as the publish-subscribe pattern.
  • 18. (ii) Iterator  According to GoF, Iterator Pattern is used "to access the elements of an aggregate object sequentially without exposing its underlying implementation".  The Iterator pattern is also known as Cursor.  In collection framework, we are now using Iterator that is preferred over Enumeration.  Iterator pattern provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation.