DOC PREVIEW
UT Dallas CS 6359 - S19_Chapter_26a

This preview shows page 1-2-14-15-30-31 out of 31 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Slide 1What will we learn?GoF Patterns - IntroductionGoF Patterns - AdapterGoF Patterns - AdapterSlide 6GoF Patterns - AdapterSlide 8Pattern OverloadThe Factory PatternThe Factory PatternSlide 12The Singleton PatternThe Singleton PatternSlide 15The Singleton PatternThe Singleton PatternThe Singleton PatternSlide 19The Strategy PatternThe Strategy PatternSlide 22The Strategy PatternSlide 24The Strategy PatternSlide 26The Strategy PatternSlide 28Slide 29Takeaways from Chapter 26Next …Object-Oriented Analysis and DesignCHAPTER 26: GOF DESIGN PATTERNS1What will we learn?We will get an introduction to the Gang of Four (GoF) PatternsWe will see how the GRASP principles are a generalization of other design patterns2GoF Patterns - Introduction The Gang of Four (GoF) patterns were introduced in the book Design Patterns There are 23 in all; we will only study a few of them here Perhaps 15 or so are commonly used Note the original book assumes a knowledge of C++ and smalltalk; we will not assume that here3GoF Patterns - Adapter The first GoF pattern we will explore is called Adapter The GRASP Polymorphism principle is a generalized version of AdapterRecall that the Polymorphism principle allowed us to define abstract classes or interfaces to handle various external objects that had similar but differing interfaces Problem: How to resolve incompatible interfaces, or provide a stable interface to similar components with different interfaces? Solution: Convert the original interface of a component into another interface, through an intermediate adapter object.4GoF Patterns - Adapter Recall the NextGen POS example; we need to support several kinds of external third party services, like tax calculators, authorization services, etc. Each of these has a different API (API: Application Progamming Interface, a set of externally facing public operations – methods - that are supported by the entity exposing the API). The solution is to add a level of indirection with a new class that “adapts” the various APIs or interfaces into one interface that can be used by the objects in our system Note that the Adapter class is not abstract – it is instantiated, and there is an adapter class for each of the various external services or systems being “adapted” The Adapter class may, however, utilize a common interface that is used by the other objects in the system56TaxMasterAdaptergetTaxes( Sale ) : List of TaxLineItemsGoodAsGoldTaxProAdaptergetTaxes( Sale ) : List of TaxLineItems«interface»ITaxCalculatorAdaptergetTaxes( Sale ) : List of TaxLineItemsAdapters use interfaces and polymorphism to add a level of indirection to varying APIs in other components.SAPAccountingAdapterpostReceivable( CreditPayment )postSale( Sale )...GreatNorthernAccountingAdapterpostReceivable( CreditPayment )postSale( Sale )...«interface»IAccountingAdapterpostReceivable( CreditPayment )postSale( Sale )...«interface»IInventoryAdapter...«interface»ICreditAuthorizationServiceAdapterrequestApproval(CreditPayment,TerminalID, MerchantID)...GoF Patterns - Adapter Notice the relationship to the GRASP principles:The Adapter uses the GRASP principles of Indirection, Pure Fabrication, and Polymorphism However, Adapter is a more concrete solution – it describes how to solve the problem with a specific class construction Guideline: If you are creating an Adapter class, always a good idea to include the word “Adapter” in the class name – helps identify the class in the design model SAPAccountingAdapter When adapters are created for resources, the GoF pattern is also called a Façade pattern (discussed later)78:Register : SAPAccountingAdapterpostSale( sale )makePaymentthe Adapter adapts to interfaces in other componentsSOAP over HTTPxxx...«actor»: SAPSystemPattern Overload We noted that Adapter can be considered a variation of Pure Fabrication, Indirection, and Polymorphism There are literally hundreds of patterns that have been identified We will try to concentrate on the underlying basic themes, which are often common to many of the patterns So while Adapter is a pattern that demonstrates Polymorphism, Indirection, and Pure Fabrication, these principles are ways to supporting Low Coupling and High Cohesion, all of which support Protected Variation. 9The Factory Pattern Also called Simple Factory or Concrete Factory. Technically not a GoF Pattern, but widely used. GoF has a pattern called Abstract Factory which is related Here is the problem: In situations such as the case we just saw when Adapter classes are used, who creates the Adapters? If there are several possible adapters in the design, how does the system determine which adapter to create? Note that this is not part of the usual application logic that would be known by domain objectsRelated more to software connectivity (to external systems, e.g.) Always a good idea to design with the intent to modularize or separate out the various concerns of the system – leads to high cohesion of the objectsSo using Register to create the Adapters is probably not a good idea10The Factory Pattern A common solution is to use what is called a Factory Pattern This is a special case of Pure Fabrication: We define a class with the sole purpose to create objects, an “object factory” This helps keep the other objects (like domain objects) more cohesiveHelps to hide the logic of creating the classes, which may be complex for some external systemsWe can also use smarter algorithms for creating the classes to enhance code performance (memory saving, object recycling, etc.) Problem: Who should be responsible for creating objects when there are special considerations, such as a complex creation logic, a need to separate creation responsibilities, etc. ? Solution: Create a Pure Fabrication object called a Factory that handles the creation.1112ServicesFactoryaccountingAdapter : IAccountingAdapterinventoryAdapter : IInventoryAdaptertaxCalculatorAdapter : ITaxCalculatorAdapter getAccountingAdapter() : IAccountingAdaptergetInventoryAdapter() : IInventoryAdaptergetTaxCalculatorAdapter() : ITaxCalculatorAdapter...note that the factory methods return objects typed to an interface rather than a class, so that the factory can return any implementation of the interface if ( taxCalculatorAdapter == null ) { // a reflective or data-driven approach to finding the right class: read it from an // external property String className = System.getProperty( "taxcalculator.class.name" );


View Full Document

UT Dallas CS 6359 - S19_Chapter_26a

Documents in this Course
Lecture2

Lecture2

63 pages

Lecture3

Lecture3

49 pages

Lecture4

Lecture4

48 pages

Lecture5

Lecture5

47 pages

Lecture6

Lecture6

45 pages

Lecture7

Lecture7

63 pages

Lecture8

Lecture8

77 pages

Lecture9

Lecture9

48 pages

Lecture10

Lecture10

84 pages

Lecture11

Lecture11

45 pages

Lecture12

Lecture12

134 pages

Lecture13

Lecture13

62 pages

Lecture14

Lecture14

76 pages

Project

Project

2 pages

Chapter_1

Chapter_1

25 pages

Load more
Download S19_Chapter_26a
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view S19_Chapter_26a and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view S19_Chapter_26a 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?