SlideShare uma empresa Scribd logo
1 de 18
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.

Mais conteúdo relacionado

Mais procurados

Reoprt on indutrial training
Reoprt on indutrial trainingReoprt on indutrial training
Reoprt on indutrial trainingPratikKhodwe1
 
Learning uml 2_part_1
Learning uml 2_part_1Learning uml 2_part_1
Learning uml 2_part_1Mark Gaad
 
Design patterns through refactoring
Design patterns through refactoringDesign patterns through refactoring
Design patterns through refactoringGanesh Samarthyam
 
Code Craftsmanship Checklist
Code Craftsmanship ChecklistCode Craftsmanship Checklist
Code Craftsmanship ChecklistRyan Polk
 
Introduction to Design Patterns
Introduction to Design PatternsIntroduction to Design Patterns
Introduction to Design PatternsJoao 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 ProgrammingAnumod Kumar
 
Modelling the User Interface
Modelling the User InterfaceModelling the User Interface
Modelling the User InterfacePedro 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 frontlinesRonald 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 TutorialTushar Sharma
 
Software Architecture: Principles, Patterns and Practices
Software Architecture: Principles, Patterns and PracticesSoftware Architecture: Principles, Patterns and Practices
Software Architecture: Principles, Patterns and PracticesGanesh Samarthyam
 
Refactoring for Software Design Smells
Refactoring for Software Design SmellsRefactoring for Software Design Smells
Refactoring for Software Design SmellsGanesh 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
 

Mais procurados (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
 

Semelhante a Oops design pattern intro

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 EngineeringProtelo, 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
 
Software design and Architecture.pptx
Software design and Architecture.pptxSoftware design and Architecture.pptx
Software design and Architecture.pptxSHAHZAIBABBAS13
 
Module 2 design patterns-2
Module 2   design patterns-2Module 2   design patterns-2
Module 2 design patterns-2Ankit Dubey
 
Introduction To Design Patterns
Introduction To Design PatternsIntroduction To Design Patterns
Introduction To Design Patternssukumarraju6
 
Unit No 6 Design Patterns.pptx
Unit No 6 Design Patterns.pptxUnit No 6 Design Patterns.pptx
Unit No 6 Design Patterns.pptxDrYogeshDeshmukh1
 
Practical OOP In Java
Practical OOP In JavaPractical OOP In Java
Practical OOP In Javawiradikusuma
 
Object-Oriented Programming in Java.pdf
Object-Oriented Programming in Java.pdfObject-Oriented Programming in Java.pdf
Object-Oriented Programming in Java.pdfBharath Choudhary
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design patternMindfire 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 WorldSaurabh Moody
 
Dynamic component composition
Dynamic component compositionDynamic component composition
Dynamic component compositionijseajournal
 
Ujjwalreverseengineeringppptfinal
UjjwalreverseengineeringppptfinalUjjwalreverseengineeringppptfinal
Ujjwalreverseengineeringppptfinalujjwalchauhan87
 

Semelhante a 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
 

Mais de anshu_atri

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

Mais de 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
 

Último

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 

Último (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 

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.