Presentation is loading. Please wait.

Presentation is loading. Please wait.

March 200391.3913 R McFadyen1 Façade. March 200391.3913 R McFadyen2 Facade P. 368+ Main Entry: fa·cade Variant(s): also fa·çade / f&-'säd/ Function: noun.

Similar presentations


Presentation on theme: "March 200391.3913 R McFadyen1 Façade. March 200391.3913 R McFadyen2 Facade P. 368+ Main Entry: fa·cade Variant(s): also fa·çade / f&-'säd/ Function: noun."— Presentation transcript:

1 March 200391.3913 R McFadyen1 Façade

2 March 200391.3913 R McFadyen2 Facade P. 368+ Main Entry: fa·cade Variant(s): also fa·çade / f&-'säd/ Function: noun Etymology: French façade, from Italian facciata, from faccia face, from (assumed) Vulgar Latin facia Date: circa 1681 1 : the front of a building; also : any face of a building given special architectural treatment 2 : a false, superficial, or artificial appearance or effect From www.m-w.com

3 March 200391.3913 R McFadyen3 Facade P. 368+ Problem: There are a set of classes, a subsystem, that you need to interact with for some purpose, but you don’t want to create dependencies on this subsystem. Solution: Create a class that wraps this subsystem. The wrapper will define an interface that hides the details (classes, methods) of the subsystem. The façade is a “front-end” object that defines a single point of entry to the subsystem’s services. Showing the classes as a package (a subsytem) A façade, a wrapper

4 March 200391.3913 R McFadyen4 Facade P. 368+ Text example. NextGen POS is a system to be sold to many customers. Customers will want to customize NextGen POS Example: Payment rules may vary for gift certificates. How are gift certificates to be handled: One per customer per purchase? No change is returned - another gift certificate issued? To allow flexibility, it is desired to reduce the impact of changes to the rest of the system To reduce the impact, the Façade pattern is applied and the subsytem will be hidden behind a single object

5 March 200391.3913 R McFadyen5 Sale objects, in the Domain package, access the POS Rule Engine via the façade in the POSRuleEngine package if ( POSRuleEngineFacade.getInstance().isInvalid(…)... On page 370: Public class Sale … ASIDE: on Page 371 - mention of the Singleton pattern Figure 23.19

6 March 200391.3913 R McFadyen6 if ( POSRuleEngineFacade.getInstance().isInvalid(…)... On page 370: Public class Sale … ASIDE: on Page 371 - mention of the Singleton pattern Singleton is a pattern whereby one instance of an object of some class is created/allowed. The class will have a static method that returns the singleton. Façades are normally accessed via the Singleton pattern.

7 March 200391.3913 R McFadyen7 Facade :Sale:POSRuleEngineFacade isInvalid (…) [valid] add (…) : makeLineItem() :SalesLineItem......

8 March 200391.3913 R McFadyen8 Example: (from Design Patterns Explained by Shalloway & Trott) Suppose a client object must deal with Databases, Models, and Elements. The client must first open the Database, then get a Model, then queries the Model for Elements, and finally gets Elements. I.e. Client Database Model Element

9 March 200391.3913 R McFadyen9 Example: (from Design Patterns Explained by Shalloway & Trott) It may be easier to create a Database Façade that can be used by clients I.e. ClientA Database Model Element Db Facade ClientB ClientC To use the database, one only needs to become aware of DbFacade, and learn how to use it.

10 March 200391.3913 R McFadyen10 When to use Facade (from Design Patterns Explained by Shalloway & Trott) To create a simpler interface: number of methods, number of objects one has to deal with The system being hidden may have an older, more complex interface The cost of developing the façade, and of developers learning the new interface may be less than learning the old one You may only be needing a subset of the functionality You may want to augment the functionality of the system To facilitate tracking system usage – by forcing all requests to go through a Façade class, one can easily track the usage. To facilitate subsystem replacement – only one class is affected, the Façade class. This is the motivation in Larman’s example.


Download ppt "March 200391.3913 R McFadyen1 Façade. March 200391.3913 R McFadyen2 Facade P. 368+ Main Entry: fa·cade Variant(s): also fa·çade / f&-'säd/ Function: noun."

Similar presentations


Ads by Google