Patterns (contd)Software Development ProcessDesign patte.docx

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 t.

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

Recomendados

P Training Presentation por
P Training PresentationP Training Presentation
P Training PresentationGaurav Tyagi
1.1K visualizações192 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
Design Patterns in Cocoa Touch por
Design Patterns in Cocoa TouchDesign Patterns in Cocoa Touch
Design Patterns in Cocoa TouchEliah Nikans
2.5K visualizações28 slides
Bartlesville Dot Net User Group Design Patterns por
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsJason Townsend, MBA
1.8K visualizações44 slides
Design Patterns por
Design PatternsDesign Patterns
Design PatternsRafael Coutinho
1.4K visualizações38 slides
Introduction to Design Patterns por
Introduction to Design PatternsIntroduction to Design Patterns
Introduction to Design PatternsPrageeth Sandakalum
1.4K visualizações25 slides

Mais conteúdo relacionado

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

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
Generic Repository Pattern in MVC3 Application with Entity Framework por
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
444 visualizações13 slides
Cs 1023 lec 8 design pattern (week 2) por
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
974 visualizações36 slides
Gof design patterns por
Gof design patternsGof design patterns
Gof design patternsSrikanth R Vaka
19.1K visualizações60 slides
Gof design pattern por
Gof design patternGof design pattern
Gof design patternnaveen kumar
388 visualizações43 slides
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP por
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
637 visualizações14 slides

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

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
Generic Repository Pattern in MVC3 Application with Entity Framework por Akhil Mittal
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
Akhil Mittal444 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
Gof design patterns por Srikanth R Vaka
Gof design patternsGof design patterns
Gof design patterns
Srikanth R Vaka19.1K visualizações
Gof design pattern por naveen kumar
Gof design patternGof design pattern
Gof design pattern
naveen kumar388 visualizações
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP por Ali Shah
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
Ali Shah637 visualizações
Sda 8 por AmberMughal5
Sda   8Sda   8
Sda 8
AmberMughal566 visualizações
Design patterns in brief por DUONG Trong Tan
Design patterns in briefDesign patterns in brief
Design patterns in brief
DUONG Trong Tan3.4K 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
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ... por Bill Buchan
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 Buchan470 visualizações
Introduction To Design Patterns por sukumarraju6
Introduction To Design PatternsIntroduction To Design Patterns
Introduction To Design Patterns
sukumarraju6372 visualizações
Design Patterns por imedo.de
Design PatternsDesign Patterns
Design Patterns
imedo.de901 visualizações
Object Oriented Programming In .Net por Greg Sohl
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
Greg Sohl10.9K visualizações
Design patterns por Akhilesh Joshi
Design patternsDesign patterns
Design patterns
Akhilesh Joshi224 visualizações
Programming with Objective-C por Nagendra Ram
Programming with Objective-CProgramming with Objective-C
Programming with Objective-C
Nagendra Ram1.3K visualizações
Sda 9 por AmberMughal5
Sda   9Sda   9
Sda 9
AmberMughal559 visualizações
Software Patterns por bonej010
Software PatternsSoftware Patterns
Software Patterns
bonej0101.2K visualizações
Building nTier Applications with Entity Framework Services (Part 1) por David McCarter
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 McCarter869 visualizações
Software Design Patterns por Satheesh Sukumaran
Software Design PatternsSoftware Design Patterns
Software Design Patterns
Satheesh Sukumaran1.2K visualizações
Software Design Patterns por Satheesh Sukumaran
Software Design PatternsSoftware Design Patterns
Software Design Patterns
Satheesh Sukumaran504 visualizações

Mais de danhaley45372

Your initial post should be 300 words in length.From your re.docx por
Your initial post should be 300 words in length.From your re.docxYour initial post should be 300 words in length.From your re.docx
Your initial post should be 300 words in length.From your re.docxdanhaley45372
22 visualizações1 slide
Your initial post should be 2-3 paragraphs in length to each p.docx por
Your initial post should be 2-3 paragraphs in length to each p.docxYour initial post should be 2-3 paragraphs in length to each p.docx
Your initial post should be 2-3 paragraphs in length to each p.docxdanhaley45372
15 visualizações5 slides
Your initial post should be at least 450+ words and in APA forma.docx por
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
2 visualizações1 slide
Your initial post should be made during, Submissions after this time.docx por
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
2 visualizações2 slides
Your cover letter and application from the Week Two Written Assignme.docx por
Your cover letter and application from the Week Two Written Assignme.docxYour cover letter and application from the Week Two Written Assignme.docx
Your cover letter and application from the Week Two Written Assignme.docxdanhaley45372
3 visualizações2 slides
Your essay should address the following.(a) How  is the biologic.docx por
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
2 visualizações2 slides

Mais de danhaley45372(20)

Your initial post should be 300 words in length.From your re.docx por danhaley45372
Your initial post should be 300 words in length.From your re.docxYour initial post should be 300 words in length.From your re.docx
Your initial post should be 300 words in length.From your re.docx
danhaley4537222 visualizações
Your initial post should be 2-3 paragraphs in length to each p.docx por danhaley45372
Your initial post should be 2-3 paragraphs in length to each p.docxYour initial post should be 2-3 paragraphs in length to each p.docx
Your initial post should be 2-3 paragraphs in length to each p.docx
danhaley4537215 visualizações
Your initial post should be at least 450+ words and in APA forma.docx por danhaley45372
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
danhaley453722 visualizações
Your initial post should be made during, Submissions after this time.docx por danhaley45372
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
danhaley453722 visualizações
Your cover letter and application from the Week Two Written Assignme.docx por danhaley45372
Your cover letter and application from the Week Two Written Assignme.docxYour cover letter and application from the Week Two Written Assignme.docx
Your cover letter and application from the Week Two Written Assignme.docx
danhaley453723 visualizações
Your essay should address the following.(a) How  is the biologic.docx por danhaley45372
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
danhaley453722 visualizações
Your document should be in essay format, error-free, graduate level .docx por danhaley45372
Your document should be in essay format, error-free, graduate level .docxYour document should be in essay format, error-free, graduate level .docx
Your document should be in essay format, error-free, graduate level .docx
danhaley453722 visualizações
Your initial post should be 300 words in length.  This week you .docx por danhaley45372
Your initial post should be 300 words in length.  This week you .docxYour initial post should be 300 words in length.  This week you .docx
Your initial post should be 300 words in length.  This week you .docx
danhaley453722 visualizações
Your initial post should be at least 200 words, formatted and .docx por danhaley45372
Your initial post should be at least 200 words, formatted and .docxYour initial post should be at least 200 words, formatted and .docx
Your initial post should be at least 200 words, formatted and .docx
danhaley453722 visualizações
Your initial post must be at least 750 words.This week you will .docx por danhaley45372
Your initial post must be at least 750 words.This week you will .docxYour initial post must be at least 750 words.This week you will .docx
Your initial post must be at least 750 words.This week you will .docx
danhaley453723 visualizações
Your initial post is due by midnight (1159 PM) on Thursday. You mus.docx por danhaley45372
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
danhaley453725 visualizações
Your initial post for this discussion should be 250-300 words..docx por danhaley45372
Your initial post for this discussion should be 250-300 words..docxYour initial post for this discussion should be 250-300 words..docx
Your initial post for this discussion should be 250-300 words..docx
danhaley453725 visualizações
Your individual sub-topic written (MIN of 1, MAX 3 pages)You.docx por danhaley45372
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
danhaley453722 visualizações
Your Individual Summary Assessment document should be double spa.docx por danhaley45372
Your Individual Summary Assessment document should be double spa.docxYour Individual Summary Assessment document should be double spa.docx
Your Individual Summary Assessment document should be double spa.docx
danhaley453722 visualizações
Your Immersion Project for this course is essentially ethnographic r.docx por danhaley45372
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
danhaley453725 visualizações
Your Individual 4 page Summary Assessment on Hello Fresh should be d.docx por danhaley45372
Your Individual 4 page Summary Assessment on Hello Fresh should be d.docxYour Individual 4 page Summary Assessment on Hello Fresh should be d.docx
Your Individual 4 page Summary Assessment on Hello Fresh should be d.docx
danhaley453723 visualizações
Your healthcare organization is going through difficult times. Patie.docx por danhaley45372
Your healthcare organization is going through difficult times. Patie.docxYour healthcare organization is going through difficult times. Patie.docx
Your healthcare organization is going through difficult times. Patie.docx
danhaley453722 visualizações
Your HR consulting organization has been approached by a potenti.docx por danhaley45372
Your HR consulting organization has been approached by a potenti.docxYour HR consulting organization has been approached by a potenti.docx
Your HR consulting organization has been approached by a potenti.docx
danhaley453722 visualizações
Your HR Development Specialist was looking through your text, which .docx por danhaley45372
Your HR Development Specialist was looking through your text, which .docxYour HR Development Specialist was looking through your text, which .docx
Your HR Development Specialist was looking through your text, which .docx
danhaley453722 visualizações
Your healthcare organization has a history of adopting technology an.docx por danhaley45372
Your healthcare organization has a history of adopting technology an.docxYour healthcare organization has a history of adopting technology an.docx
Your healthcare organization has a history of adopting technology an.docx
danhaley453722 visualizações

Último

Are we onboard yet University of Sussex.pptx por
Are we onboard yet University of Sussex.pptxAre we onboard yet University of Sussex.pptx
Are we onboard yet University of Sussex.pptxJisc
93 visualizações7 slides
ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1} por
ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1}ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1}
ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1}DR .PALLAVI PATHANIA
244 visualizações195 slides
ACTIVITY BOOK key water sports.pptx por
ACTIVITY BOOK key water sports.pptxACTIVITY BOOK key water sports.pptx
ACTIVITY BOOK key water sports.pptxMar Caston Palacio
511 visualizações4 slides
REPRESENTATION - GAUNTLET.pptx por
REPRESENTATION - GAUNTLET.pptxREPRESENTATION - GAUNTLET.pptx
REPRESENTATION - GAUNTLET.pptxiammrhaywood
91 visualizações26 slides
Psychology KS5 por
Psychology KS5Psychology KS5
Psychology KS5WestHatch
81 visualizações5 slides
Structure and Functions of Cell.pdf por
Structure and Functions of Cell.pdfStructure and Functions of Cell.pdf
Structure and Functions of Cell.pdfNithya Murugan
455 visualizações10 slides

Último(20)

Are we onboard yet University of Sussex.pptx por Jisc
Are we onboard yet University of Sussex.pptxAre we onboard yet University of Sussex.pptx
Are we onboard yet University of Sussex.pptx
Jisc93 visualizações
ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1} por DR .PALLAVI PATHANIA
ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1}ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1}
ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1}
DR .PALLAVI PATHANIA244 visualizações
ACTIVITY BOOK key water sports.pptx por Mar Caston Palacio
ACTIVITY BOOK key water sports.pptxACTIVITY BOOK key water sports.pptx
ACTIVITY BOOK key water sports.pptx
Mar Caston Palacio511 visualizações
REPRESENTATION - GAUNTLET.pptx por iammrhaywood
REPRESENTATION - GAUNTLET.pptxREPRESENTATION - GAUNTLET.pptx
REPRESENTATION - GAUNTLET.pptx
iammrhaywood91 visualizações
Psychology KS5 por WestHatch
Psychology KS5Psychology KS5
Psychology KS5
WestHatch81 visualizações
Structure and Functions of Cell.pdf por Nithya Murugan
Structure and Functions of Cell.pdfStructure and Functions of Cell.pdf
Structure and Functions of Cell.pdf
Nithya Murugan455 visualizações
Sociology KS5 por WestHatch
Sociology KS5Sociology KS5
Sociology KS5
WestHatch65 visualizações
Class 10 English notes 23-24.pptx por TARIQ KHAN
Class 10 English notes 23-24.pptxClass 10 English notes 23-24.pptx
Class 10 English notes 23-24.pptx
TARIQ KHAN125 visualizações
CWP_23995_2013_17_11_2023_FINAL_ORDER.pdf por SukhwinderSingh895865
CWP_23995_2013_17_11_2023_FINAL_ORDER.pdfCWP_23995_2013_17_11_2023_FINAL_ORDER.pdf
CWP_23995_2013_17_11_2023_FINAL_ORDER.pdf
SukhwinderSingh895865518 visualizações
Women from Hackney’s History: Stoke Newington by Sue Doe por History of Stoke Newington
Women from Hackney’s History: Stoke Newington by Sue DoeWomen from Hackney’s History: Stoke Newington by Sue Doe
Women from Hackney’s History: Stoke Newington by Sue Doe
History of Stoke Newington148 visualizações
AUDIENCE - BANDURA.pptx por iammrhaywood
AUDIENCE - BANDURA.pptxAUDIENCE - BANDURA.pptx
AUDIENCE - BANDURA.pptx
iammrhaywood77 visualizações
AI Tools for Business and Startups por Svetlin Nakov
AI Tools for Business and StartupsAI Tools for Business and Startups
AI Tools for Business and Startups
Svetlin Nakov105 visualizações
7 NOVEL DRUG DELIVERY SYSTEM.pptx por Sachin Nitave
7 NOVEL DRUG DELIVERY SYSTEM.pptx7 NOVEL DRUG DELIVERY SYSTEM.pptx
7 NOVEL DRUG DELIVERY SYSTEM.pptx
Sachin Nitave59 visualizações
11.28.23 Social Capital and Social Exclusion.pptx por mary850239
11.28.23 Social Capital and Social Exclusion.pptx11.28.23 Social Capital and Social Exclusion.pptx
11.28.23 Social Capital and Social Exclusion.pptx
mary850239291 visualizações
231112 (WR) v1 ChatGPT OEB 2023.pdf por WilfredRubens.com
231112 (WR) v1  ChatGPT OEB 2023.pdf231112 (WR) v1  ChatGPT OEB 2023.pdf
231112 (WR) v1 ChatGPT OEB 2023.pdf
WilfredRubens.com151 visualizações
Use of Probiotics in Aquaculture.pptx por AKSHAY MANDAL
Use of Probiotics in Aquaculture.pptxUse of Probiotics in Aquaculture.pptx
Use of Probiotics in Aquaculture.pptx
AKSHAY MANDAL95 visualizações
UWP OA Week Presentation (1).pptx por Jisc
UWP OA Week Presentation (1).pptxUWP OA Week Presentation (1).pptx
UWP OA Week Presentation (1).pptx
Jisc87 visualizações
Education and Diversity.pptx por DrHafizKosar
Education and Diversity.pptxEducation and Diversity.pptx
Education and Diversity.pptx
DrHafizKosar135 visualizações

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