SlideShare a Scribd company logo
1 of 12
Patterns (contd)
Software Development Process
Design patterns used to handle change
More time extending and changing code than developing it.
The Strategy design pattern handle change by selecting from a
family of external algorithms rather than rewrite.
Design point: Make code closed for modification of code, but
open for extension
Problem
Computer object created
Description Method returns
Getting a Computer
Problem
Program has to change every time
Customer changes options
Decorator Pattern
Wrapper code used to extend your core code
Extend a class dynamically at runtime
Decorator uses wrapper code to extend core functionality -
decorating the code
Decorator Pattern
description() returns “You are getting a computer”
Wrapper description() returns
“You are getting a computer and a disk”
Wrapper description() returns
“You are getting a computer and a disk and a monitor”
Decorator Pattern
Core component: Computer
Variables holding computer objects should also be able to hold
objects that wrap computer objects.
Extend the wrapper classes from the Computer class.
Abstract class cannot be instantiated
Ensures all wrappers are consistent
Developers have to provide their own description
Decorator Pattern
Method calls the core computer object’s
description method and adds “and a disk”
Decorator Pattern
Method calls the core computer object’s
description method and adds “and a disk”
Extend the core object by wrapping it in decorator wrappers.
Avoids modification of the core code.
Each successive wrapper called the description method of the
object it wrapped and added something to it.
Factory Pattern
Based on type, call the
Connection method
Factory Pattern
Create a method that returns the
correct connection type
Factory Pattern
New operator used to create OracleConnection objects.
New operator used to create SqlServerConnection objects, and
MySqlConnection objects.
New operator to instantiate many different concrete classes
Code becomes larger and needs to be replicated in many places
Factor that code out into a method.
Code keeps changing
Encapsulate code into a factory object
Goal: Separate out the changeable code and leave the core code
closed for modification
Building the Factory
Creating the Factory
FirstFactory class encapsulates the connection object creation
Pass to it the type of connection (“Oracle”, “SQL Server”,)
Use the factory object to create connection objects with a
factory method named createConnection
Building the Factory
Create the FirstFactory class.
Save the type of the database, passed to the FirstFactory class’s
constructor.
Object-creation code changes
Check which type of object to be created
(OracleConnection, SqlServerConnection,
and then create it.
Factory Class
Create the Abstract Connection Class
Core code should not be modified or has to be modified
as little as possible.
Using the connection object returned by the
new factory object
Use the same code for all the different types of
connection objects
Code should be polymorphic — all connection objects
should share the same interface or be derived from
the same base class.
Able to use the same variable for any created object
Make the Connection Class Abstract
Derive all the objects your factory creates from the
same base class or interface
Code that uses the objects it creates doesn’t have to be
modified for each new object type.
Creating Concrete Connection Class
Testing it Out
The Observer Pattern
Subject informs a set of Observers about a Change or Event
The Observer Pattern
The Observer Pattern
Chain of Responsibility Pattern
Coupling
The Observer and Chain of Responsibility design patterns
implement loose coupling
Hard coding command handling results in a large, monolithic
class that’s hard to debug or even understand.
Encapsulated objects through simple notifications rather than
hard coding a connection.
Flexibility and robustness.
Self-contained objects: easier to debug and develop semi-
independent objects
Design Guideline: loose coupling between objects, rather than
extending objects is good design policy
Singleton Pattern
Singleton design pattern only one object of a particular class
throughout your code
New operator just keeps on creating more and more objects of
the same class
Use the Singleton design pattern when you want to restrict
resource use or when you have an object whose data shouldn’t
be accessed by multiple instances (such as a registry or multi-
threading).
Singleton Pattern
Singleton pattern creates only one object from a specific class
irrespective of number of times your code tries to create it.
Sensitive objects where conflicts cannot be permitted
Example: windowsRegistry.
Singleton pattern takes control over the object instantiation
process away from the new operator
Flyweight Pattern
The Flyweight pattern
Code uses many large objects — using up system resources
Fix by using a smaller set of template objects configured on-
the-fly (run time) to look like those larger objects.
The configurable objects — the flyweights — are fewer, smaller
and reusable
After configuration they will appear to the rest of your code as
though you still have many large objects.
Flyweight Pattern
Flyweight Pattern
Takes time to configure a flyweight object,
If configurations are constantly changing, lose much of the
performance gains.
Extracting a generic template class from existing objects in
order to create flyweight objects
Adding a layer of programming, which make maintenance and
extension harder.
Adapter Pattern
The Adapter design pattern fixes the interface between objects
and classes without having to modify the objects or classes
directly.
Off-the-shelf solution cannot change what one application
produces to make it compatible to another application.
Adapter Pattern
Façade Pattern
The Facade design pattern makes an OOP interface easier to
use.
If an object or class interface is too hard to work with, the
Facade pattern gives you a front end to that interface to make it
easier.
facade simplifies the interface between a class or object and the
code that makes use of that class or object
Façade Pattern
For effective OOP, classes of objects should not have to know
too much about each other.
Details should be inside each class or object and make the
coupling between entities as loose as possible
If an object needs to know too much about another make their
coupling loose by using a Facade pattern
Quiz
What are the building blocks of Object Oriented Programming
(OOP)? Why are Design Patterns used in developing systems?
Which building block of OOP is used by Design Patterns?
Why?
Observer Pattern
Pass notifications when an event occurs
Java Event notifications
Object Oriented Programming
General principle: break up programs into manageable units
Functional programming: break into functions
Insufficient for large programs:
Solution
to break programs into objects, incorporate functions
(behavior) within object description
Wrapping functionality into objects makes them easy to
conceptualize
Display wraps the display function of your program into the
object
Database all the database connectivity
OOP Building Blocks
Abstraction
Encapsulation
Polymorphism
Programs that can handle different object types at run time
Inheritance
One class inherit methods and properties from another
Design Oriented Programming
Polymorphism preferred since design patterns tend to favor
composition over inheritance.
Inheritance make code rigid making maintenance difficult.
Design oriented programming uses composition objects contains
other objects
Composition vs. Inheritance
Task: Design New Classes of Vehicles
Method: Indicates the Driving mode
Street Racer extends Vehicle
Invoke Method: Shows the Driving mode
Composition vs. Inheritance
New Class: Formula One racer
Composition vs. Inheritance
New Class: Helicopter
Problem: A single task is accomplished — driving a car or
flying a helicopter — across several generations of classes
Tasks that change often result in having to edit several classes
becomes a maintenance issue.
Tip: avoid spreading out the handling of a particular,
changeable tasks over several generations of classes
Composition vs. Inheritance
Problem
Each class and subclass still has to implement its own version
of the go method
Interfaces require custom code in each class
Possible

More Related Content

Similar to Patterns (contd)Software Development ProcessDesign patte.docx

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
 
Generic Repository Pattern in MVC3 Application with Entity Framework
Generic Repository Pattern in MVC3 Application with Entity FrameworkGeneric Repository Pattern in MVC3 Application with Entity Framework
Generic Repository Pattern in MVC3 Application with Entity FrameworkAkhil Mittal
 
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
 
Gof design pattern
Gof design patternGof design pattern
Gof design patternnaveen kumar
 
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISPMCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISPAli Shah
 
Design patterns in brief
Design patterns in briefDesign patterns in brief
Design patterns in briefDUONG Trong Tan
 
Unit 2-Design Patterns.ppt
Unit 2-Design Patterns.pptUnit 2-Design Patterns.ppt
Unit 2-Design Patterns.pptMsRAMYACSE
 
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...Bill Buchan
 
Introduction To Design Patterns
Introduction To Design PatternsIntroduction To Design Patterns
Introduction To Design Patternssukumarraju6
 
Design Patterns
Design PatternsDesign Patterns
Design Patternsimedo.de
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .NetGreg Sohl
 
Programming with Objective-C
Programming with Objective-CProgramming with Objective-C
Programming with Objective-CNagendra Ram
 
Software Patterns
Software PatternsSoftware Patterns
Software Patternsbonej010
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)David McCarter
 

Similar to Patterns (contd)Software Development ProcessDesign patte.docx (20)

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
 
Generic Repository Pattern in MVC3 Application with Entity Framework
Generic Repository Pattern in MVC3 Application with Entity FrameworkGeneric Repository Pattern in MVC3 Application with Entity Framework
Generic Repository Pattern in MVC3 Application with Entity Framework
 
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)
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
 
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISPMCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
 
Sda 8
Sda   8Sda   8
Sda 8
 
Design patterns in brief
Design patterns in briefDesign patterns in brief
Design patterns in brief
 
Unit 2-Design Patterns.ppt
Unit 2-Design Patterns.pptUnit 2-Design Patterns.ppt
Unit 2-Design Patterns.ppt
 
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
 
Introduction To Design Patterns
Introduction To Design PatternsIntroduction To Design Patterns
Introduction To Design Patterns
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Programming with Objective-C
Programming with Objective-CProgramming with Objective-C
Programming with Objective-C
 
Sda 9
Sda   9Sda   9
Sda 9
 
Software Patterns
Software PatternsSoftware Patterns
Software Patterns
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 

More from danhaley45372

Your initial post should be 2-3 paragraphs in length.Inclu.docx
Your initial post should be 2-3 paragraphs in length.Inclu.docxYour initial post should be 2-3 paragraphs in length.Inclu.docx
Your initial post should be 2-3 paragraphs in length.Inclu.docxdanhaley45372
 
Your initial post should be made during Unit 2,  January 21st at 4.docx
Your initial post should be made during Unit 2,  January 21st at 4.docxYour initial post should be made during Unit 2,  January 21st at 4.docx
Your initial post should be made during Unit 2,  January 21st at 4.docxdanhaley45372
 
Your initial post should be at least 450+ words and in APA forma.docx
Your initial post should be at least 450+ words and in APA forma.docxYour initial post should be at least 450+ words and in APA forma.docx
Your initial post should be at least 450+ words and in APA forma.docxdanhaley45372
 
Your initial post should be made during Unit 2, january 21st at 4.docx
Your initial post should be made during Unit 2, january 21st at 4.docxYour initial post should be made during Unit 2, january 21st at 4.docx
Your initial post should be made during Unit 2, january 21st at 4.docxdanhaley45372
 
Your initial post should be made during, Submissions after this time.docx
Your initial post should be made during, Submissions after this time.docxYour initial post should be made during, Submissions after this time.docx
Your initial post should be made during, Submissions after this time.docxdanhaley45372
 
Your essay should address the following.(a) How  is the biologic.docx
Your essay should address the following.(a) How  is the biologic.docxYour essay should address the following.(a) How  is the biologic.docx
Your essay should address the following.(a) How  is the biologic.docxdanhaley45372
 
Your initial post is due by midnight (1159 PM) on Thursday. You mus.docx
Your initial post is due by midnight (1159 PM) on Thursday. You mus.docxYour initial post is due by midnight (1159 PM) on Thursday. You mus.docx
Your initial post is due by midnight (1159 PM) on Thursday. You mus.docxdanhaley45372
 
Your individual sub-topic written (MIN of 1, MAX 3 pages)You.docx
Your individual sub-topic written (MIN of 1, MAX 3 pages)You.docxYour individual sub-topic written (MIN of 1, MAX 3 pages)You.docx
Your individual sub-topic written (MIN of 1, MAX 3 pages)You.docxdanhaley45372
 
Your HR project to develop a centralized model of deliveri.docx
Your HR project to develop a centralized model of deliveri.docxYour HR project to develop a centralized model of deliveri.docx
Your HR project to develop a centralized model of deliveri.docxdanhaley45372
 
Your Immersion Project for this course is essentially ethnographic r.docx
Your Immersion Project for this course is essentially ethnographic r.docxYour Immersion Project for this course is essentially ethnographic r.docx
Your Immersion Project for this course is essentially ethnographic r.docxdanhaley45372
 
Your country just overthrew its dictator, and you are the newly .docx
Your country just overthrew its dictator, and you are the newly .docxYour country just overthrew its dictator, and you are the newly .docx
Your country just overthrew its dictator, and you are the newly .docxdanhaley45372
 
Your have been contracted by HealthFirst Hospital Foundation (HHF),.docx
Your have been contracted by HealthFirst Hospital Foundation (HHF),.docxYour have been contracted by HealthFirst Hospital Foundation (HHF),.docx
Your have been contracted by HealthFirst Hospital Foundation (HHF),.docxdanhaley45372
 
Your group presentationWhat you need to do.docx
Your group presentationWhat you need to do.docxYour group presentationWhat you need to do.docx
Your group presentationWhat you need to do.docxdanhaley45372
 
Your contribution(s) must add significant information to the dis.docx
Your contribution(s) must add significant information to the dis.docxYour contribution(s) must add significant information to the dis.docx
Your contribution(s) must add significant information to the dis.docxdanhaley45372
 
Your good friends have just adopted a four-year-old child. At th.docx
Your good friends have just adopted a four-year-old child. At th.docxYour good friends have just adopted a four-year-old child. At th.docx
Your good friends have just adopted a four-year-old child. At th.docxdanhaley45372
 
Your good friends have just adopted a four-year-old child. At this p.docx
Your good friends have just adopted a four-year-old child. At this p.docxYour good friends have just adopted a four-year-old child. At this p.docx
Your good friends have just adopted a four-year-old child. At this p.docxdanhaley45372
 
Your goals as the IT architect and IT security specialist are to.docx
Your goals as the IT architect and IT security specialist are to.docxYour goals as the IT architect and IT security specialist are to.docx
Your goals as the IT architect and IT security specialist are to.docxdanhaley45372
 
Your essay should address the following problem.(a) What is .docx
Your essay should address the following problem.(a) What is .docxYour essay should address the following problem.(a) What is .docx
Your essay should address the following problem.(a) What is .docxdanhaley45372
 
Your future financial needs will be based on the income you can reas.docx
Your future financial needs will be based on the income you can reas.docxYour future financial needs will be based on the income you can reas.docx
Your future financial needs will be based on the income you can reas.docxdanhaley45372
 
Your friend Lydia is having difficulty taking in the informati.docx
Your friend Lydia is having difficulty taking in the informati.docxYour friend Lydia is having difficulty taking in the informati.docx
Your friend Lydia is having difficulty taking in the informati.docxdanhaley45372
 

More from danhaley45372 (20)

Your initial post should be 2-3 paragraphs in length.Inclu.docx
Your initial post should be 2-3 paragraphs in length.Inclu.docxYour initial post should be 2-3 paragraphs in length.Inclu.docx
Your initial post should be 2-3 paragraphs in length.Inclu.docx
 
Your initial post should be made during Unit 2,  January 21st at 4.docx
Your initial post should be made during Unit 2,  January 21st at 4.docxYour initial post should be made during Unit 2,  January 21st at 4.docx
Your initial post should be made during Unit 2,  January 21st at 4.docx
 
Your initial post should be at least 450+ words and in APA forma.docx
Your initial post should be at least 450+ words and in APA forma.docxYour initial post should be at least 450+ words and in APA forma.docx
Your initial post should be at least 450+ words and in APA forma.docx
 
Your initial post should be made during Unit 2, january 21st at 4.docx
Your initial post should be made during Unit 2, january 21st at 4.docxYour initial post should be made during Unit 2, january 21st at 4.docx
Your initial post should be made during Unit 2, january 21st at 4.docx
 
Your initial post should be made during, Submissions after this time.docx
Your initial post should be made during, Submissions after this time.docxYour initial post should be made during, Submissions after this time.docx
Your initial post should be made during, Submissions after this time.docx
 
Your essay should address the following.(a) How  is the biologic.docx
Your essay should address the following.(a) How  is the biologic.docxYour essay should address the following.(a) How  is the biologic.docx
Your essay should address the following.(a) How  is the biologic.docx
 
Your initial post is due by midnight (1159 PM) on Thursday. You mus.docx
Your initial post is due by midnight (1159 PM) on Thursday. You mus.docxYour initial post is due by midnight (1159 PM) on Thursday. You mus.docx
Your initial post is due by midnight (1159 PM) on Thursday. You mus.docx
 
Your individual sub-topic written (MIN of 1, MAX 3 pages)You.docx
Your individual sub-topic written (MIN of 1, MAX 3 pages)You.docxYour individual sub-topic written (MIN of 1, MAX 3 pages)You.docx
Your individual sub-topic written (MIN of 1, MAX 3 pages)You.docx
 
Your HR project to develop a centralized model of deliveri.docx
Your HR project to develop a centralized model of deliveri.docxYour HR project to develop a centralized model of deliveri.docx
Your HR project to develop a centralized model of deliveri.docx
 
Your Immersion Project for this course is essentially ethnographic r.docx
Your Immersion Project for this course is essentially ethnographic r.docxYour Immersion Project for this course is essentially ethnographic r.docx
Your Immersion Project for this course is essentially ethnographic r.docx
 
Your country just overthrew its dictator, and you are the newly .docx
Your country just overthrew its dictator, and you are the newly .docxYour country just overthrew its dictator, and you are the newly .docx
Your country just overthrew its dictator, and you are the newly .docx
 
Your have been contracted by HealthFirst Hospital Foundation (HHF),.docx
Your have been contracted by HealthFirst Hospital Foundation (HHF),.docxYour have been contracted by HealthFirst Hospital Foundation (HHF),.docx
Your have been contracted by HealthFirst Hospital Foundation (HHF),.docx
 
Your group presentationWhat you need to do.docx
Your group presentationWhat you need to do.docxYour group presentationWhat you need to do.docx
Your group presentationWhat you need to do.docx
 
Your contribution(s) must add significant information to the dis.docx
Your contribution(s) must add significant information to the dis.docxYour contribution(s) must add significant information to the dis.docx
Your contribution(s) must add significant information to the dis.docx
 
Your good friends have just adopted a four-year-old child. At th.docx
Your good friends have just adopted a four-year-old child. At th.docxYour good friends have just adopted a four-year-old child. At th.docx
Your good friends have just adopted a four-year-old child. At th.docx
 
Your good friends have just adopted a four-year-old child. At this p.docx
Your good friends have just adopted a four-year-old child. At this p.docxYour good friends have just adopted a four-year-old child. At this p.docx
Your good friends have just adopted a four-year-old child. At this p.docx
 
Your goals as the IT architect and IT security specialist are to.docx
Your goals as the IT architect and IT security specialist are to.docxYour goals as the IT architect and IT security specialist are to.docx
Your goals as the IT architect and IT security specialist are to.docx
 
Your essay should address the following problem.(a) What is .docx
Your essay should address the following problem.(a) What is .docxYour essay should address the following problem.(a) What is .docx
Your essay should address the following problem.(a) What is .docx
 
Your future financial needs will be based on the income you can reas.docx
Your future financial needs will be based on the income you can reas.docxYour future financial needs will be based on the income you can reas.docx
Your future financial needs will be based on the income you can reas.docx
 
Your friend Lydia is having difficulty taking in the informati.docx
Your friend Lydia is having difficulty taking in the informati.docxYour friend Lydia is having difficulty taking in the informati.docx
Your friend Lydia is having difficulty taking in the informati.docx
 

Recently uploaded

Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxsqpmdrvczh
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 

Recently uploaded (20)

Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptx
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 

Patterns (contd)Software Development ProcessDesign patte.docx

  • 1. Patterns (contd) Software Development Process Design patterns used to handle change More time extending and changing code than developing it. The Strategy design pattern handle change by selecting from a family of external algorithms rather than rewrite. Design point: Make code closed for modification of code, but open for extension Problem Computer object created Description Method returns Getting a Computer Problem Program has to change every time Customer changes options Decorator Pattern Wrapper code used to extend your core code Extend a class dynamically at runtime Decorator uses wrapper code to extend core functionality - decorating the code Decorator Pattern
  • 2. description() returns “You are getting a computer” Wrapper description() returns “You are getting a computer and a disk” Wrapper description() returns “You are getting a computer and a disk and a monitor” Decorator Pattern Core component: Computer Variables holding computer objects should also be able to hold objects that wrap computer objects. Extend the wrapper classes from the Computer class. Abstract class cannot be instantiated Ensures all wrappers are consistent Developers have to provide their own description Decorator Pattern Method calls the core computer object’s description method and adds “and a disk” Decorator Pattern Method calls the core computer object’s description method and adds “and a disk”
  • 3. Extend the core object by wrapping it in decorator wrappers. Avoids modification of the core code. Each successive wrapper called the description method of the object it wrapped and added something to it. Factory Pattern Based on type, call the Connection method Factory Pattern Create a method that returns the correct connection type Factory Pattern New operator used to create OracleConnection objects. New operator used to create SqlServerConnection objects, and MySqlConnection objects. New operator to instantiate many different concrete classes Code becomes larger and needs to be replicated in many places Factor that code out into a method. Code keeps changing Encapsulate code into a factory object Goal: Separate out the changeable code and leave the core code closed for modification
  • 4. Building the Factory Creating the Factory FirstFactory class encapsulates the connection object creation Pass to it the type of connection (“Oracle”, “SQL Server”,) Use the factory object to create connection objects with a factory method named createConnection Building the Factory Create the FirstFactory class. Save the type of the database, passed to the FirstFactory class’s constructor. Object-creation code changes Check which type of object to be created (OracleConnection, SqlServerConnection, and then create it. Factory Class Create the Abstract Connection Class Core code should not be modified or has to be modified as little as possible. Using the connection object returned by the new factory object Use the same code for all the different types of connection objects Code should be polymorphic — all connection objects should share the same interface or be derived from the same base class.
  • 5. Able to use the same variable for any created object Make the Connection Class Abstract Derive all the objects your factory creates from the same base class or interface Code that uses the objects it creates doesn’t have to be modified for each new object type. Creating Concrete Connection Class Testing it Out The Observer Pattern Subject informs a set of Observers about a Change or Event The Observer Pattern The Observer Pattern Chain of Responsibility Pattern
  • 6. Coupling The Observer and Chain of Responsibility design patterns implement loose coupling Hard coding command handling results in a large, monolithic class that’s hard to debug or even understand. Encapsulated objects through simple notifications rather than hard coding a connection. Flexibility and robustness. Self-contained objects: easier to debug and develop semi- independent objects Design Guideline: loose coupling between objects, rather than extending objects is good design policy Singleton Pattern Singleton design pattern only one object of a particular class throughout your code New operator just keeps on creating more and more objects of the same class Use the Singleton design pattern when you want to restrict resource use or when you have an object whose data shouldn’t be accessed by multiple instances (such as a registry or multi- threading). Singleton Pattern Singleton pattern creates only one object from a specific class
  • 7. irrespective of number of times your code tries to create it. Sensitive objects where conflicts cannot be permitted Example: windowsRegistry. Singleton pattern takes control over the object instantiation process away from the new operator Flyweight Pattern The Flyweight pattern Code uses many large objects — using up system resources Fix by using a smaller set of template objects configured on- the-fly (run time) to look like those larger objects. The configurable objects — the flyweights — are fewer, smaller and reusable After configuration they will appear to the rest of your code as though you still have many large objects. Flyweight Pattern Flyweight Pattern Takes time to configure a flyweight object, If configurations are constantly changing, lose much of the performance gains. Extracting a generic template class from existing objects in order to create flyweight objects Adding a layer of programming, which make maintenance and extension harder. Adapter Pattern The Adapter design pattern fixes the interface between objects and classes without having to modify the objects or classes
  • 8. directly. Off-the-shelf solution cannot change what one application produces to make it compatible to another application. Adapter Pattern Façade Pattern The Facade design pattern makes an OOP interface easier to use. If an object or class interface is too hard to work with, the Facade pattern gives you a front end to that interface to make it easier. facade simplifies the interface between a class or object and the code that makes use of that class or object Façade Pattern For effective OOP, classes of objects should not have to know too much about each other. Details should be inside each class or object and make the coupling between entities as loose as possible If an object needs to know too much about another make their coupling loose by using a Facade pattern Quiz What are the building blocks of Object Oriented Programming (OOP)? Why are Design Patterns used in developing systems?
  • 9. Which building block of OOP is used by Design Patterns? Why? Observer Pattern Pass notifications when an event occurs Java Event notifications Object Oriented Programming General principle: break up programs into manageable units Functional programming: break into functions Insufficient for large programs: Solution to break programs into objects, incorporate functions (behavior) within object description Wrapping functionality into objects makes them easy to conceptualize Display wraps the display function of your program into the object Database all the database connectivity
  • 10. OOP Building Blocks Abstraction Encapsulation Polymorphism Programs that can handle different object types at run time Inheritance One class inherit methods and properties from another Design Oriented Programming Polymorphism preferred since design patterns tend to favor composition over inheritance. Inheritance make code rigid making maintenance difficult. Design oriented programming uses composition objects contains other objects Composition vs. Inheritance Task: Design New Classes of Vehicles Method: Indicates the Driving mode Street Racer extends Vehicle
  • 11. Invoke Method: Shows the Driving mode Composition vs. Inheritance New Class: Formula One racer Composition vs. Inheritance New Class: Helicopter Problem: A single task is accomplished — driving a car or flying a helicopter — across several generations of classes Tasks that change often result in having to edit several classes becomes a maintenance issue. Tip: avoid spreading out the handling of a particular, changeable tasks over several generations of classes
  • 12. Composition vs. Inheritance Problem Each class and subclass still has to implement its own version of the go method Interfaces require custom code in each class Possible