Sda 8

SOFTWARE DESIGN AND ARCHITECTURE
LECTURE 24-26
Disclaimer: The contents of this
presentation have been taken from
multiple sources, i.e. Books,
Research articles, Thesis
publications, and websites.
The material used in this presentation i.e., pictures/graphs/text, etc. is solely
intended for educational/teaching purpose, offered free of cost to the students for
use under special circumstances of Online Education due to COVID-19 Lockdown
situation and may include copyrighted material - the use of which may not have
been specifically authorised by Copyright Owners. It’s application constitutes Fair
Use of any such copyrighted material as provided in globally accepted law of many
countries. The contents of presentations are intended only for the attendees of the
class being conducted by the presenter.
Fair Use Notice
Outlines
Creational Design Patterns
Singleton,
Abstract Factory,
Builder,
Prototype
Why study design pattern?
Experts in software architecture and design are highly paid, because they know how to create
designs that are flexible, elegant, and reusable.
You become an expert through experience, reusing solutions that worked for you before.
Patterns describe solutions to design problems that occur over and over again.
SINGLETON Pattern
Intent: Ensure a class only has one instance, and provide a global point of access to it.
Motivation: In many systems, there should often only be one object instance for a given class
Print spooler
File system
Window manager
How do we ensure that a class has only one instance and that the instance is easily accessible?
the singleton pattern is a software design pattern that restricts the instantiation of a class to
one "single" instance. This is useful when exactly one object is needed to coordinate actions
across the system.
Creating A Single Instance
This maybe necessary because:
More than one instance will result in incorrect program behavior
More than one instance will result in the overuse of resources
There is a need for a global point of access
Sda   8
SINGLETON Pattern
Applicability
Use the Singleton pattern when
there must be exactly one instance of a class, and it must be accessible to clients from a well-known
access point
Make the class of the single instance object responsible for creation, initialization, access, and
enforcement. Declare the instance as a private static data member. Provide a public static member
function that encapsulates all initialization code, and provides access to the instance.
SINGLETON Pattern: Structure
Singleton
static uniqueInstance
singletonData
static instance()
singletonOperation()
getSingletonData()
return uniqueInstance
SINGLETON Pattern: Consequences
Controlled access to sole instance
As the constructor is private, the class controls when an instance is created
Reduced name space
Eliminates the need for global variables that store single instances
Permits refinement of operations and representations
You can easily sub-class the Singleton
SINGLETON PATTERN: Implementation
public class ClassicSingleton
{
private static ClassicSingleton instance = null; variable
private ClassicSingleton() { // Exists only to defeat instantiation. } constructor outsider
accesss na krske
public static ClassicSingleton getInstance() { method
if(instance == null)
{ instance = new ClassicSingleton(); }
return instance;
}
}
EASY LOOK
Singleton Pattern
Known use: A known use for singleton pattern is where a global resource is shared, Also used
with metaclasses.
Related Patterns: Many patterns can be implemented using the Singleton pattern.
AbstractFactory, Builder, Prototype.
There are two forms of singleton design pattern
Early Instantiation: creation of instance at load time.
Lazy Instantiation: creation of instance when required.
Example
The Singleton pattern ensures that a class has only one instance and provides a global point of
access to that instance. It is named after the singleton set, which is defined to be a set
containing one element. The office of the President of the United States is a Singleton. The
United States Constitution specifies the means by which a president is elected, limits the term of
office, and defines the order of succession. As a result, there can be at most one active
president at any given time. Regardless of the personal identity of the active president, the title,
"The President of the United States" is a global point of access that identifies the person in the
office.
Example 2 - Configuration Classes
The Singleton pattern is used to design the classes which provides the configuration settings for an
application. By implementing configuration classes as Singleton not only that we provide a global access
point, but we also keep the instance we use as a cache object. When the class is instantiated( or when a
value is read ) the singleton will keep the values in its internal structure. If the values are read from the
database or from files this avoids the reloading the values each time the configuration parameters are
used.
Abstract Factory Pattern
The Abstract Factory design pattern falls under the Creational design pattern category and it
provides a way to encapsulate a group of factories that have a common link without highlighting
their concrete classes.
In Abstract Factory pattern an interface is responsible for creating a factory of related objects
without explicitly specifying their classes. Each generated factory can give the objects as per the
Factory pattern.
Abstract Factory Pattern
Abstract Factory Pattern Participants
•AbstractFactory : Declares an interface for operations that create abstract product
objects.
•ConcreteFactory : Implements the operations declared in the AbstractFactory to
create concrete product objects.
•Product : Defines a product object to be created by the corresponding concrete
factory and implements the AbstractProduct interface.
•Client : Uses only interfaces declared by AbstractFactory and AbstractProduct
classes.
Sda   8
Factory
Kitchen
Abstract Factory Pattern
Abstract Factory Pattern
How Factory Pattern works in Real Life ?
1 Orders a Dish from Menu
2
Receives the Order
Creates the Dish
4 Delivers the Dish
3 Outsources to Chef
Abstract Factory Pattern
Motivation
Consider a garments factory specialized in creating trousers and shirts. Now the Parent company which
is a famous Retail brand is now venturing into Gadget section. They are also planning to expand their
Factories having one centre in US and another one in UK. The client should be completely unaware of
how the objects are created. What is the best design pattern we can use to resolve this requirement?
Abstract Factory Pattern
Applicability
Use the Abstract Factory pattern when
a system should be independent of how its products are created, composed, and represented.
a system should be configured with one of multiple families of products.
you want to provide a class library of products, and you want to reveal just their interfaces, not their
implementations.
You can be sure that the products you’re getting from a factory are compatible with each other.
The code may become more complicated than it should be, since a lot of new interfaces and classes are
introduced along with the pattern.
Abstract Factory Pattern
Abstract Factory Pattern
Builder Pattern
Builder is a creational design pattern that lets you construct complex objects step by step. The
pattern allows you to produce different types and representations of an object using the same
construction code.
Motivation
For example, you can consider construction of a home. Home is the final end product (object) that is to
be returned as the output of the construction process. It will have many steps, like basement
construction, wall construction and so on roof construction. Finally the whole home object is returned.
Here using the same process you can build houses with different properties.
Consider a class which is used to create Cake, now you need number of items like egg, milk, flour to
create cake. many of them are mandatory and some of them are optional like cherry, fruits etc.
What is the difference between abstract
factory and builder pattern?
Abstract factory may also be used to construct a complex object, then what is the difference
with builder pattern?
In builder pattern emphasis is on ‘step by step’.
Builder pattern will have many number of small steps. Those every steps will have small units of logic
enclosed in it.
There will also be a sequence involved.
It will start from step 1 and will go upto step n and the final step is returning the object.
In these steps, every step will add some value in construction of the object. That is you can imagine that
the object grows stage by stage.
Builder will return the object in last step, but in abstract factory how complex the built object might be,
it will not have step by step object construction.
Sda   8
Applicability
Use the Builder pattern when
 the algorithm for creating a complex object should be independent of the parts that make up the object and how
they're assembled.
 the construction process must allow different representations for the object that's constructed.
When you want to hide creation process from the user.
Builder Pattern
Sda   8
Sda   8
Sda   8
Sda   8
Builder Pattern- Structure
The following interaction diagram illustrates how Builder and Director cooperate with a client
Builder Pattern
Consequences
It lets you vary a product's internal representation.
It isolates code for construction and representation.
It gives you finer control over the construction process.
Builder Pattern
Prototype Pattern
A prototype is a template of any object before the actual object is constructed.
Prototype is a creational design pattern that lets you copy existing objects without making your
code dependent on their classes.
Prototype design pattern is used in scenarios where application needs to create a number of
instances of a class, which has almost same state or differs very little.
Intent
Specify the kinds of objects to create using a prototypical instance, and create new objects by copying
this prototype.
Sda   8
Prototype Pattern
Motivation
Today’s programming is all about costs. Saving is a big issue when it comes to using computer resources,
so programmers are doing their best to find ways of improving the performance When we talk about
object creation we can find a better way to have new objects: cloning.
To this idea one particular design pattern is related: rather than creation it uses cloning. If the cost of
creating a new object is large and creation is resource intensive, we clone the object.
Say you have an object, and you want to create an exact copy of it. How would you do it? First, you have to create a
new object of the same class. Then you have to go through all the fields of the original object and copy their values
over to the new object.
Nice! But there’s a catch. Not all objects can be copied that way because some of the object’s fields may be private
and not visible from outside of the object itself.
Sda   8
Prototype Pattern
This pattern involves implementing a prototype interface which tells to create a clone of the
current object.
For example, a object is to be created after a costly database operation. We can cache the
object, returns its clone on next request and update the database as and when needed thus
reducing database calls.
Prototype Pattern
Applicability
Use the Prototype pattern
when a system should be independent of how its products are created, composed, and represented; and
when the classes to instantiate are specified at run-time, for example, by dynamic loading; or
when instances of a class can have one of only a few different combinations of state. It may be more convenient to
install a corresponding number of prototypes and clone them rather than instantiating the class manually, each
time with the appropriate state.
Prototype Pattern
Structure
Prototype Pattern
Implementation (tips and problems)
The prototype design pattern mandates that the instance which you are going to copy should provide
the copying feature. It should not be done by an external utility or provider.
Also make sure that instance allows you to make changes to the data. If not, after cloning you will not
be able to make required changes to get the new required object.
Using a prototype manager (a registry service)
Prototype Pattern
Sample Application’s Structure
1 de 46

Recomendados

Design patterns por
Design patternsDesign patterns
Design patternsmudabbirwarsi
1.8K visualizações22 slides
Design patterns por
Design patternsDesign patterns
Design patternsElyes Mejri
337 visualizações38 slides
Design patterns por
Design patternsDesign patterns
Design patternsAnas Alpure
163 visualizações42 slides
Software Design Patterns por
Software Design PatternsSoftware Design Patterns
Software Design PatternsSatheesh Sukumaran
1.2K visualizações26 slides
Let us understand design pattern por
Let us understand design patternLet us understand design pattern
Let us understand design patternMindfire Solutions
35.8K visualizações45 slides
Composite design pattern por
Composite design patternComposite design pattern
Composite design patternMUHAMMAD FARHAN ASLAM
175 visualizações15 slides

Mais conteúdo relacionado

Mais procurados

JAVA design patterns and Basic OOp concepts por
JAVA design patterns and Basic OOp conceptsJAVA design patterns and Basic OOp concepts
JAVA design patterns and Basic OOp conceptsRahul Malhotra
3K visualizações32 slides
Behavioral pattern By:-Priyanka Pradhan por
Behavioral pattern By:-Priyanka PradhanBehavioral pattern By:-Priyanka Pradhan
Behavioral pattern By:-Priyanka Pradhanpriyanka pradhan
5.1K visualizações27 slides
Lecture 5 Software Engineering and Design Design Patterns por
Lecture 5 Software Engineering and Design Design PatternsLecture 5 Software Engineering and Design Design Patterns
Lecture 5 Software Engineering and Design Design Patternsop205
8.6K visualizações23 slides
GOF Design pattern with java por
GOF Design pattern with javaGOF Design pattern with java
GOF Design pattern with javaRajiv Gupta
673 visualizações52 slides
GoF Design patterns I: Introduction + Structural Patterns por
GoF Design patterns I:   Introduction + Structural PatternsGoF Design patterns I:   Introduction + Structural Patterns
GoF Design patterns I: Introduction + Structural PatternsSameh Deabes
3.1K visualizações38 slides
Design Pattern For C# Part 1 por
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1Shahzad
7.1K visualizações19 slides

Mais procurados(20)

JAVA design patterns and Basic OOp concepts por Rahul Malhotra
JAVA design patterns and Basic OOp conceptsJAVA design patterns and Basic OOp concepts
JAVA design patterns and Basic OOp concepts
Rahul Malhotra3K visualizações
Behavioral pattern By:-Priyanka Pradhan por priyanka pradhan
Behavioral pattern By:-Priyanka PradhanBehavioral pattern By:-Priyanka Pradhan
Behavioral pattern By:-Priyanka Pradhan
priyanka pradhan5.1K visualizações
Lecture 5 Software Engineering and Design Design Patterns por op205
Lecture 5 Software Engineering and Design Design PatternsLecture 5 Software Engineering and Design Design Patterns
Lecture 5 Software Engineering and Design Design Patterns
op2058.6K visualizações
GOF Design pattern with java por Rajiv Gupta
GOF Design pattern with javaGOF Design pattern with java
GOF Design pattern with java
Rajiv Gupta673 visualizações
GoF Design patterns I: Introduction + Structural Patterns por Sameh Deabes
GoF Design patterns I:   Introduction + Structural PatternsGoF Design patterns I:   Introduction + Structural Patterns
GoF Design patterns I: Introduction + Structural Patterns
Sameh Deabes3.1K visualizações
Design Pattern For C# Part 1 por Shahzad
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
Shahzad 7.1K visualizações
Software Design Patterns. Part I :: Structural Patterns por Sergey Aganezov
Software Design Patterns. Part I :: Structural PatternsSoftware Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural Patterns
Sergey Aganezov691 visualizações
Design pattern-presentation por Rana Muhammad Asif
Design pattern-presentationDesign pattern-presentation
Design pattern-presentation
Rana Muhammad Asif3.2K visualizações
Design Patterns por soms_1
Design PatternsDesign Patterns
Design Patterns
soms_114.2K visualizações
Design Patterns por Anuja Arosha
Design PatternsDesign Patterns
Design Patterns
Anuja Arosha13.5K visualizações
Structural patterns por Himanshu
Structural patternsStructural patterns
Structural patterns
Himanshu 6.4K visualizações
Design pattern por Thibaut De Broca
Design patternDesign pattern
Design pattern
Thibaut De Broca3.8K visualizações
Basic design pattern interview questions por jinaldesailive
Basic design pattern interview questionsBasic design pattern interview questions
Basic design pattern interview questions
jinaldesailive17.5K visualizações
Design patterns difference between interview questions por Umar Ali
Design patterns   difference between interview questionsDesign patterns   difference between interview questions
Design patterns difference between interview questions
Umar Ali10.4K visualizações
Introduction to Design Pattern por Sanae BEKKAR
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
Sanae BEKKAR17K visualizações
Design Patterns Presentation - Chetan Gole por Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan Gole
Chetan Gole12.1K visualizações
Design patterns ppt por Aman Jain
Design patterns pptDesign patterns ppt
Design patterns ppt
Aman Jain28.7K visualizações
PATTERNS04 - Structural Design Patterns por Michael Heron
PATTERNS04 - Structural Design PatternsPATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design Patterns
Michael Heron1.4K visualizações
Design Patterns - General Introduction por Asma CHERIF
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
Asma CHERIF627 visualizações

Similar a Sda 8

Jump start to OOP, OOAD, and Design Pattern por
Jump start to OOP, OOAD, and Design PatternJump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternNishith Shukla
9.8K visualizações58 slides
Jump Start To Ooad And Design Patterns por
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsLalit Kale
1.2K visualizações58 slides
Creational Design Patterns.pptx por
Creational Design Patterns.pptxCreational Design Patterns.pptx
Creational Design Patterns.pptxSachin Patidar
13 visualizações25 slides
Typescript design patterns applied to sharepoint framework - Sharepoint Satur... por
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
603 visualizações31 slides
Patterns (contd)Software Development ProcessDesign patte.docx por
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxdanhaley45372
4 visualizações12 slides
Introduction to Design Patterns por
Introduction to Design PatternsIntroduction to Design Patterns
Introduction to Design PatternsPrageeth Sandakalum
1.4K visualizações25 slides

Similar a Sda 8(20)

Jump start to OOP, OOAD, and Design Pattern por Nishith Shukla
Jump start to OOP, OOAD, and Design PatternJump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design Pattern
Nishith Shukla9.8K visualizações
Jump Start To Ooad And Design Patterns por Lalit Kale
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design Patterns
Lalit Kale1.2K visualizações
Creational Design Patterns.pptx por Sachin Patidar
Creational Design Patterns.pptxCreational Design Patterns.pptx
Creational Design Patterns.pptx
Sachin Patidar13 visualizações
Typescript design patterns applied to sharepoint framework - Sharepoint Satur... por Luis Valencia
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 Valencia603 visualizações
Patterns (contd)Software Development ProcessDesign patte.docx por danhaley45372
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
danhaley453724 visualizações
Introduction to Design Patterns por Prageeth Sandakalum
Introduction to Design PatternsIntroduction to Design Patterns
Introduction to Design Patterns
Prageeth Sandakalum1.4K visualizações
Gof design patterns por Srikanth R Vaka
Gof design patternsGof design patterns
Gof design patterns
Srikanth R Vaka19.1K visualizações
Unit 2-Design Patterns.ppt por MsRAMYACSE
Unit 2-Design Patterns.pptUnit 2-Design Patterns.ppt
Unit 2-Design Patterns.ppt
MsRAMYACSE125 visualizações
P Training Presentation por Gaurav Tyagi
P Training PresentationP Training Presentation
P Training Presentation
Gaurav Tyagi1.1K visualizações
Creational pattern por Himanshu
Creational patternCreational pattern
Creational pattern
Himanshu 3.3K visualizações
Software Patterns por bonej010
Software PatternsSoftware Patterns
Software Patterns
bonej0101.2K visualizações
Layers of Smalltalk Application por speludner
Layers of Smalltalk ApplicationLayers of Smalltalk Application
Layers of Smalltalk Application
speludner432 visualizações
Design Patterns por Rafael Coutinho
Design PatternsDesign Patterns
Design Patterns
Rafael Coutinho1.4K visualizações
UNIT IV DESIGN PATTERNS.pptx por anguraju1
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptx
anguraju13 visualizações
Design pattern por Shreyance Jain
Design patternDesign pattern
Design pattern
Shreyance Jain469 visualizações
7 software design patterns you should know in 2022 por Growth Natives
7 software design patterns you should know in 20227 software design patterns you should know in 2022
7 software design patterns you should know in 2022
Growth Natives111 visualizações
Why Design Patterns Are Important In Software Engineering por Protelo, Inc.
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.4.6K visualizações
Design Patterns por Sergii Stets
Design PatternsDesign Patterns
Design Patterns
Sergii Stets344 visualizações
Cs 1023 lec 8 design pattern (week 2) por stanbridge
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)
stanbridge974 visualizações

Mais de AmberMughal5

Sda 9 por
Sda   9Sda   9
Sda 9AmberMughal5
59 visualizações33 slides
Sda 7 por
Sda   7Sda   7
Sda 7AmberMughal5
47 visualizações34 slides
Sda 6 por
Sda   6Sda   6
Sda 6AmberMughal5
57 visualizações24 slides
Sda 4 por
Sda   4Sda   4
Sda 4AmberMughal5
48 visualizações54 slides
Sda 3 por
Sda   3Sda   3
Sda 3AmberMughal5
47 visualizações38 slides
Sda 2 por
Sda   2Sda   2
Sda 2AmberMughal5
56 visualizações29 slides

Mais de AmberMughal5(8)

Sda 9 por AmberMughal5
Sda   9Sda   9
Sda 9
AmberMughal559 visualizações
Sda 7 por AmberMughal5
Sda   7Sda   7
Sda 7
AmberMughal547 visualizações
Sda 6 por AmberMughal5
Sda   6Sda   6
Sda 6
AmberMughal557 visualizações
Sda 4 por AmberMughal5
Sda   4Sda   4
Sda 4
AmberMughal548 visualizações
Sda 3 por AmberMughal5
Sda   3Sda   3
Sda 3
AmberMughal547 visualizações
Sda 2 por AmberMughal5
Sda   2Sda   2
Sda 2
AmberMughal556 visualizações
Sda 1 por AmberMughal5
Sda   1Sda   1
Sda 1
AmberMughal572 visualizações
Sa03 tactics por AmberMughal5
Sa03 tacticsSa03 tactics
Sa03 tactics
AmberMughal5480 visualizações

Último

_MAKRIADI-FOTEINI_diploma thesis.pptx por
_MAKRIADI-FOTEINI_diploma thesis.pptx_MAKRIADI-FOTEINI_diploma thesis.pptx
_MAKRIADI-FOTEINI_diploma thesis.pptxfotinimakriadi
6 visualizações32 slides
2_DVD_ASIC_Design_FLow.pdf por
2_DVD_ASIC_Design_FLow.pdf2_DVD_ASIC_Design_FLow.pdf
2_DVD_ASIC_Design_FLow.pdfUsha Mehta
14 visualizações24 slides
Informed search algorithms.pptx por
Informed search algorithms.pptxInformed search algorithms.pptx
Informed search algorithms.pptxDr.Shweta
12 visualizações19 slides
An approach of ontology and knowledge base for railway maintenance por
An approach of ontology and knowledge base for railway maintenanceAn approach of ontology and knowledge base for railway maintenance
An approach of ontology and knowledge base for railway maintenanceIJECEIAES
12 visualizações14 slides
Codes and Conventions.pptx por
Codes and Conventions.pptxCodes and Conventions.pptx
Codes and Conventions.pptxIsabellaGraceAnkers
7 visualizações5 slides
MSA Website Slideshow (16).pdf por
MSA Website Slideshow (16).pdfMSA Website Slideshow (16).pdf
MSA Website Slideshow (16).pdfmsaucla
39 visualizações8 slides

Último(20)

_MAKRIADI-FOTEINI_diploma thesis.pptx por fotinimakriadi
_MAKRIADI-FOTEINI_diploma thesis.pptx_MAKRIADI-FOTEINI_diploma thesis.pptx
_MAKRIADI-FOTEINI_diploma thesis.pptx
fotinimakriadi6 visualizações
2_DVD_ASIC_Design_FLow.pdf por Usha Mehta
2_DVD_ASIC_Design_FLow.pdf2_DVD_ASIC_Design_FLow.pdf
2_DVD_ASIC_Design_FLow.pdf
Usha Mehta14 visualizações
Informed search algorithms.pptx por Dr.Shweta
Informed search algorithms.pptxInformed search algorithms.pptx
Informed search algorithms.pptx
Dr.Shweta12 visualizações
An approach of ontology and knowledge base for railway maintenance por IJECEIAES
An approach of ontology and knowledge base for railway maintenanceAn approach of ontology and knowledge base for railway maintenance
An approach of ontology and knowledge base for railway maintenance
IJECEIAES12 visualizações
Codes and Conventions.pptx por IsabellaGraceAnkers
Codes and Conventions.pptxCodes and Conventions.pptx
Codes and Conventions.pptx
IsabellaGraceAnkers7 visualizações
MSA Website Slideshow (16).pdf por msaucla
MSA Website Slideshow (16).pdfMSA Website Slideshow (16).pdf
MSA Website Slideshow (16).pdf
msaucla39 visualizações
Literature review and Case study on Commercial Complex in Nepal, Durbar mall,... por AakashShakya12
Literature review and Case study on Commercial Complex in Nepal, Durbar mall,...Literature review and Case study on Commercial Complex in Nepal, Durbar mall,...
Literature review and Case study on Commercial Complex in Nepal, Durbar mall,...
AakashShakya1245 visualizações
Update 42 models(Diode/General ) in SPICE PARK(DEC2023) por Tsuyoshi Horigome
Update 42 models(Diode/General ) in SPICE PARK(DEC2023)Update 42 models(Diode/General ) in SPICE PARK(DEC2023)
Update 42 models(Diode/General ) in SPICE PARK(DEC2023)
Tsuyoshi Horigome18 visualizações
13_DVD_Latch-up_prevention.pdf por Usha Mehta
13_DVD_Latch-up_prevention.pdf13_DVD_Latch-up_prevention.pdf
13_DVD_Latch-up_prevention.pdf
Usha Mehta9 visualizações
What is Unit Testing por Sadaaki Emura
What is Unit TestingWhat is Unit Testing
What is Unit Testing
Sadaaki Emura23 visualizações
cloud computing-virtualization.pptx por RajaulKarim20
cloud computing-virtualization.pptxcloud computing-virtualization.pptx
cloud computing-virtualization.pptx
RajaulKarim2082 visualizações
Thermal aware task assignment for multicore processors using genetic algorithm por IJECEIAES
Thermal aware task assignment for multicore processors using genetic algorithm Thermal aware task assignment for multicore processors using genetic algorithm
Thermal aware task assignment for multicore processors using genetic algorithm
IJECEIAES29 visualizações
DevOps to DevSecOps: Enhancing Software Security Throughout The Development L... por Anowar Hossain
DevOps to DevSecOps: Enhancing Software Security Throughout The Development L...DevOps to DevSecOps: Enhancing Software Security Throughout The Development L...
DevOps to DevSecOps: Enhancing Software Security Throughout The Development L...
Anowar Hossain10 visualizações
Dynamics of Hard-Magnetic Soft Materials por Shivendra Nandan
Dynamics of Hard-Magnetic Soft MaterialsDynamics of Hard-Magnetic Soft Materials
Dynamics of Hard-Magnetic Soft Materials
Shivendra Nandan13 visualizações
Performance of Back-to-Back Mechanically Stabilized Earth Walls Supporting th... por ahmedmesaiaoun
Performance of Back-to-Back Mechanically Stabilized Earth Walls Supporting th...Performance of Back-to-Back Mechanically Stabilized Earth Walls Supporting th...
Performance of Back-to-Back Mechanically Stabilized Earth Walls Supporting th...
ahmedmesaiaoun12 visualizações
SWM L15-L28_drhasan (Part 2).pdf por MahmudHasan747870
SWM L15-L28_drhasan (Part 2).pdfSWM L15-L28_drhasan (Part 2).pdf
SWM L15-L28_drhasan (Part 2).pdf
MahmudHasan74787028 visualizações

Sda 8

  • 1. SOFTWARE DESIGN AND ARCHITECTURE LECTURE 24-26 Disclaimer: The contents of this presentation have been taken from multiple sources, i.e. Books, Research articles, Thesis publications, and websites.
  • 2. The material used in this presentation i.e., pictures/graphs/text, etc. is solely intended for educational/teaching purpose, offered free of cost to the students for use under special circumstances of Online Education due to COVID-19 Lockdown situation and may include copyrighted material - the use of which may not have been specifically authorised by Copyright Owners. It’s application constitutes Fair Use of any such copyrighted material as provided in globally accepted law of many countries. The contents of presentations are intended only for the attendees of the class being conducted by the presenter. Fair Use Notice
  • 4. Why study design pattern? Experts in software architecture and design are highly paid, because they know how to create designs that are flexible, elegant, and reusable. You become an expert through experience, reusing solutions that worked for you before. Patterns describe solutions to design problems that occur over and over again.
  • 5. SINGLETON Pattern Intent: Ensure a class only has one instance, and provide a global point of access to it. Motivation: In many systems, there should often only be one object instance for a given class Print spooler File system Window manager How do we ensure that a class has only one instance and that the instance is easily accessible? the singleton pattern is a software design pattern that restricts the instantiation of a class to one "single" instance. This is useful when exactly one object is needed to coordinate actions across the system.
  • 6. Creating A Single Instance This maybe necessary because: More than one instance will result in incorrect program behavior More than one instance will result in the overuse of resources There is a need for a global point of access
  • 8. SINGLETON Pattern Applicability Use the Singleton pattern when there must be exactly one instance of a class, and it must be accessible to clients from a well-known access point Make the class of the single instance object responsible for creation, initialization, access, and enforcement. Declare the instance as a private static data member. Provide a public static member function that encapsulates all initialization code, and provides access to the instance.
  • 9. SINGLETON Pattern: Structure Singleton static uniqueInstance singletonData static instance() singletonOperation() getSingletonData() return uniqueInstance
  • 10. SINGLETON Pattern: Consequences Controlled access to sole instance As the constructor is private, the class controls when an instance is created Reduced name space Eliminates the need for global variables that store single instances Permits refinement of operations and representations You can easily sub-class the Singleton
  • 11. SINGLETON PATTERN: Implementation public class ClassicSingleton { private static ClassicSingleton instance = null; variable private ClassicSingleton() { // Exists only to defeat instantiation. } constructor outsider accesss na krske public static ClassicSingleton getInstance() { method if(instance == null) { instance = new ClassicSingleton(); } return instance; } }
  • 13. Singleton Pattern Known use: A known use for singleton pattern is where a global resource is shared, Also used with metaclasses. Related Patterns: Many patterns can be implemented using the Singleton pattern. AbstractFactory, Builder, Prototype. There are two forms of singleton design pattern Early Instantiation: creation of instance at load time. Lazy Instantiation: creation of instance when required.
  • 14. Example The Singleton pattern ensures that a class has only one instance and provides a global point of access to that instance. It is named after the singleton set, which is defined to be a set containing one element. The office of the President of the United States is a Singleton. The United States Constitution specifies the means by which a president is elected, limits the term of office, and defines the order of succession. As a result, there can be at most one active president at any given time. Regardless of the personal identity of the active president, the title, "The President of the United States" is a global point of access that identifies the person in the office.
  • 15. Example 2 - Configuration Classes The Singleton pattern is used to design the classes which provides the configuration settings for an application. By implementing configuration classes as Singleton not only that we provide a global access point, but we also keep the instance we use as a cache object. When the class is instantiated( or when a value is read ) the singleton will keep the values in its internal structure. If the values are read from the database or from files this avoids the reloading the values each time the configuration parameters are used.
  • 16. Abstract Factory Pattern The Abstract Factory design pattern falls under the Creational design pattern category and it provides a way to encapsulate a group of factories that have a common link without highlighting their concrete classes. In Abstract Factory pattern an interface is responsible for creating a factory of related objects without explicitly specifying their classes. Each generated factory can give the objects as per the Factory pattern.
  • 18. Abstract Factory Pattern Participants •AbstractFactory : Declares an interface for operations that create abstract product objects. •ConcreteFactory : Implements the operations declared in the AbstractFactory to create concrete product objects. •Product : Defines a product object to be created by the corresponding concrete factory and implements the AbstractProduct interface. •Client : Uses only interfaces declared by AbstractFactory and AbstractProduct classes.
  • 22. How Factory Pattern works in Real Life ? 1 Orders a Dish from Menu 2 Receives the Order Creates the Dish 4 Delivers the Dish 3 Outsources to Chef Abstract Factory Pattern
  • 23. Motivation Consider a garments factory specialized in creating trousers and shirts. Now the Parent company which is a famous Retail brand is now venturing into Gadget section. They are also planning to expand their Factories having one centre in US and another one in UK. The client should be completely unaware of how the objects are created. What is the best design pattern we can use to resolve this requirement? Abstract Factory Pattern
  • 24. Applicability Use the Abstract Factory pattern when a system should be independent of how its products are created, composed, and represented. a system should be configured with one of multiple families of products. you want to provide a class library of products, and you want to reveal just their interfaces, not their implementations. You can be sure that the products you’re getting from a factory are compatible with each other. The code may become more complicated than it should be, since a lot of new interfaces and classes are introduced along with the pattern. Abstract Factory Pattern
  • 26. Builder Pattern Builder is a creational design pattern that lets you construct complex objects step by step. The pattern allows you to produce different types and representations of an object using the same construction code. Motivation For example, you can consider construction of a home. Home is the final end product (object) that is to be returned as the output of the construction process. It will have many steps, like basement construction, wall construction and so on roof construction. Finally the whole home object is returned. Here using the same process you can build houses with different properties. Consider a class which is used to create Cake, now you need number of items like egg, milk, flour to create cake. many of them are mandatory and some of them are optional like cherry, fruits etc.
  • 27. What is the difference between abstract factory and builder pattern? Abstract factory may also be used to construct a complex object, then what is the difference with builder pattern? In builder pattern emphasis is on ‘step by step’. Builder pattern will have many number of small steps. Those every steps will have small units of logic enclosed in it. There will also be a sequence involved. It will start from step 1 and will go upto step n and the final step is returning the object. In these steps, every step will add some value in construction of the object. That is you can imagine that the object grows stage by stage. Builder will return the object in last step, but in abstract factory how complex the built object might be, it will not have step by step object construction.
  • 29. Applicability Use the Builder pattern when  the algorithm for creating a complex object should be independent of the parts that make up the object and how they're assembled.  the construction process must allow different representations for the object that's constructed. When you want to hide creation process from the user. Builder Pattern
  • 35. The following interaction diagram illustrates how Builder and Director cooperate with a client Builder Pattern
  • 36. Consequences It lets you vary a product's internal representation. It isolates code for construction and representation. It gives you finer control over the construction process. Builder Pattern
  • 37. Prototype Pattern A prototype is a template of any object before the actual object is constructed. Prototype is a creational design pattern that lets you copy existing objects without making your code dependent on their classes. Prototype design pattern is used in scenarios where application needs to create a number of instances of a class, which has almost same state or differs very little. Intent Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.
  • 39. Prototype Pattern Motivation Today’s programming is all about costs. Saving is a big issue when it comes to using computer resources, so programmers are doing their best to find ways of improving the performance When we talk about object creation we can find a better way to have new objects: cloning. To this idea one particular design pattern is related: rather than creation it uses cloning. If the cost of creating a new object is large and creation is resource intensive, we clone the object.
  • 40. Say you have an object, and you want to create an exact copy of it. How would you do it? First, you have to create a new object of the same class. Then you have to go through all the fields of the original object and copy their values over to the new object. Nice! But there’s a catch. Not all objects can be copied that way because some of the object’s fields may be private and not visible from outside of the object itself.
  • 42. Prototype Pattern This pattern involves implementing a prototype interface which tells to create a clone of the current object. For example, a object is to be created after a costly database operation. We can cache the object, returns its clone on next request and update the database as and when needed thus reducing database calls.
  • 43. Prototype Pattern Applicability Use the Prototype pattern when a system should be independent of how its products are created, composed, and represented; and when the classes to instantiate are specified at run-time, for example, by dynamic loading; or when instances of a class can have one of only a few different combinations of state. It may be more convenient to install a corresponding number of prototypes and clone them rather than instantiating the class manually, each time with the appropriate state.
  • 45. Prototype Pattern Implementation (tips and problems) The prototype design pattern mandates that the instance which you are going to copy should provide the copying feature. It should not be done by an external utility or provider. Also make sure that instance allows you to make changes to the data. If not, after cloning you will not be able to make required changes to get the new required object. Using a prototype manager (a registry service)