SlideShare a Scribd company logo
1 of 46
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
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.
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.
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
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.
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.
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

More Related Content

What's hot

JAVA design patterns and Basic OOp concepts
JAVA design patterns and Basic OOp conceptsJAVA design patterns and Basic OOp concepts
JAVA design patterns and Basic OOp conceptsRahul Malhotra
 
Behavioral pattern By:-Priyanka Pradhan
Behavioral pattern By:-Priyanka PradhanBehavioral pattern By:-Priyanka Pradhan
Behavioral pattern By:-Priyanka PradhanPriyanka Pradhan
 
Lecture 5 Software Engineering and Design Design Patterns
Lecture 5 Software Engineering and Design Design PatternsLecture 5 Software Engineering and Design Design Patterns
Lecture 5 Software Engineering and Design Design Patternsop205
 
GOF Design pattern with java
GOF Design pattern with javaGOF Design pattern with java
GOF Design pattern with javaRajiv Gupta
 
GoF Design patterns I: Introduction + Structural Patterns
GoF Design patterns I:   Introduction + Structural PatternsGoF Design patterns I:   Introduction + Structural Patterns
GoF Design patterns I: Introduction + Structural PatternsSameh Deabes
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1Shahzad
 
Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSoftware Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSergey Aganezov
 
Design Patterns
Design PatternsDesign Patterns
Design Patternssoms_1
 
Structural patterns
Structural patternsStructural patterns
Structural patternsHimanshu
 
Basic design pattern interview questions
Basic design pattern interview questionsBasic design pattern interview questions
Basic design pattern interview questionsjinaldesailive
 
Design patterns difference between interview questions
Design patterns   difference between interview questionsDesign patterns   difference between interview questions
Design patterns difference between interview questionsUmar Ali
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design PatternSanae BEKKAR
 
Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan GoleChetan Gole
 
Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns pptAman Jain
 
PATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design PatternsPATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design PatternsMichael Heron
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General IntroductionAsma CHERIF
 

What's hot (20)

JAVA design patterns and Basic OOp concepts
JAVA design patterns and Basic OOp conceptsJAVA design patterns and Basic OOp concepts
JAVA design patterns and Basic OOp concepts
 
Behavioral pattern By:-Priyanka Pradhan
Behavioral pattern By:-Priyanka PradhanBehavioral pattern By:-Priyanka Pradhan
Behavioral pattern By:-Priyanka Pradhan
 
Lecture 5 Software Engineering and Design Design Patterns
Lecture 5 Software Engineering and Design Design PatternsLecture 5 Software Engineering and Design Design Patterns
Lecture 5 Software Engineering and Design Design Patterns
 
GOF Design pattern with java
GOF Design pattern with javaGOF Design pattern with java
GOF Design pattern with java
 
GoF Design patterns I: Introduction + Structural Patterns
GoF Design patterns I:   Introduction + Structural PatternsGoF Design patterns I:   Introduction + Structural Patterns
GoF Design patterns I: Introduction + Structural Patterns
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
 
Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSoftware Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural Patterns
 
Design pattern-presentation
Design pattern-presentationDesign pattern-presentation
Design pattern-presentation
 
Design patterns tutorials
Design patterns tutorialsDesign patterns tutorials
Design patterns tutorials
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Structural patterns
Structural patternsStructural patterns
Structural patterns
 
Design pattern
Design patternDesign pattern
Design pattern
 
Basic design pattern interview questions
Basic design pattern interview questionsBasic design pattern interview questions
Basic design pattern interview questions
 
Design patterns difference between interview questions
Design patterns   difference between interview questionsDesign patterns   difference between interview questions
Design patterns difference between interview questions
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
 
Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan Gole
 
Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns ppt
 
PATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design PatternsPATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design Patterns
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
 

Similar to Sda 8

Jump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternJump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternNishith Shukla
 
Jump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsLalit Kale
 
Creational Design Patterns.pptx
Creational Design Patterns.pptxCreational Design Patterns.pptx
Creational Design Patterns.pptxSachin Patidar
 
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
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxdanhaley45372
 
Unit 2-Design Patterns.ppt
Unit 2-Design Patterns.pptUnit 2-Design Patterns.ppt
Unit 2-Design Patterns.pptMsRAMYACSE
 
P Training Presentation
P Training PresentationP Training Presentation
P Training PresentationGaurav Tyagi
 
Creational pattern
Creational patternCreational pattern
Creational patternHimanshu
 
Software Patterns
Software PatternsSoftware Patterns
Software Patternsbonej010
 
Layers of Smalltalk Application
Layers of Smalltalk ApplicationLayers of Smalltalk Application
Layers of Smalltalk Applicationspeludner
 
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxanguraju1
 
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.
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)stanbridge
 

Similar to Sda 8 (20)

Jump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternJump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design Pattern
 
Jump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design Patterns
 
Creational Design Patterns.pptx
Creational Design Patterns.pptxCreational Design Patterns.pptx
Creational Design Patterns.pptx
 
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...
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
 
Introduction to Design Patterns
Introduction to Design PatternsIntroduction to Design Patterns
Introduction to Design Patterns
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Unit 2-Design Patterns.ppt
Unit 2-Design Patterns.pptUnit 2-Design Patterns.ppt
Unit 2-Design Patterns.ppt
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 
Creational pattern
Creational patternCreational pattern
Creational pattern
 
Software Patterns
Software PatternsSoftware Patterns
Software Patterns
 
Layers of Smalltalk Application
Layers of Smalltalk ApplicationLayers of Smalltalk Application
Layers of Smalltalk Application
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptx
 
Design pattern
Design patternDesign pattern
Design pattern
 
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
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)
 
Prototype pattern
Prototype patternPrototype pattern
Prototype pattern
 

More from AmberMughal5 (8)

Sda 9
Sda   9Sda   9
Sda 9
 
Sda 7
Sda   7Sda   7
Sda 7
 
Sda 6
Sda   6Sda   6
Sda 6
 
Sda 4
Sda   4Sda   4
Sda 4
 
Sda 3
Sda   3Sda   3
Sda 3
 
Sda 2
Sda   2Sda   2
Sda 2
 
Sda 1
Sda   1Sda   1
Sda 1
 
Sa03 tactics
Sa03 tacticsSa03 tactics
Sa03 tactics
 

Recently uploaded

Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture designssuser87fa0c1
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage examplePragyanshuParadkar1
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 

Recently uploaded (20)

Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture design
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage example
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 

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
  • 7.
  • 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.
  • 19.
  • 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.
  • 28.
  • 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
  • 30.
  • 31.
  • 32.
  • 33.
  • 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.
  • 38.
  • 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.
  • 41.
  • 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)