façade pattern jeff schott cs590l spring 2004. what is a façade? 1) the principal face or front of...

18
Façade Pattern Jeff Schott CS590L Spring 2004

Post on 15-Jan-2016

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Façade Pattern Jeff Schott CS590L Spring 2004. What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance

Façade Pattern

Jeff Schott

CS590L Spring 2004

Page 2: Façade Pattern Jeff Schott CS590L Spring 2004. What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance

What is a façade?

1) The principal face or front of a building

2) A false, superficial, or artificial appearance

Page 3: Façade Pattern Jeff Schott CS590L Spring 2004. What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance

What is the intent?

Provide a unified interface to a set of interfaces in a subsystem

Define a higher-level interface that makes a subsystem easier to use

Page 4: Façade Pattern Jeff Schott CS590L Spring 2004. What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance

Motivation

Structuring a system into subsystems helps reduce complexity

Minimize communication dependencies between subsystems

Introduce a façade that provides a single simplified interface

Page 5: Façade Pattern Jeff Schott CS590L Spring 2004. What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance

Provides a single interface to clients

Page 6: Façade Pattern Jeff Schott CS590L Spring 2004. What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance

Example - Compiler

Scanner Parser ProgramNode BytecodeStream ProgramNodeBuilder

Compiler subsystem contains classes:

Page 7: Façade Pattern Jeff Schott CS590L Spring 2004. What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance

Most clients don’t care about details like parsing and code generation

Compiler subsystem includes a Compiler class - unified interface

Page 8: Façade Pattern Jeff Schott CS590L Spring 2004. What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance

Applicability

Provide a simple interface to a complex system

Reduce dependencies between clients and implementation classes

Layered subsystems - façade provides an entry point to each layer

Page 9: Façade Pattern Jeff Schott CS590L Spring 2004. What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance

Structure

Page 10: Façade Pattern Jeff Schott CS590L Spring 2004. What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance

Benefits

Shields clients from subsystem components Promotes weak coupling between the

subsystem and clients Doesn’t prevent clients from accessing

subsystem classes if necessary

Page 11: Façade Pattern Jeff Schott CS590L Spring 2004. What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance

Implementation Considerations

Coupling between clients and the subsystem can be further reduced by making the façade an abstract class

Public v. Private subsystem classes

Page 12: Façade Pattern Jeff Schott CS590L Spring 2004. What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance

Sample Code

Page 13: Façade Pattern Jeff Schott CS590L Spring 2004. What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance

Sample Code

Page 14: Façade Pattern Jeff Schott CS590L Spring 2004. What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance

Sample Code

Page 15: Façade Pattern Jeff Schott CS590L Spring 2004. What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance

Sample Code

Page 16: Façade Pattern Jeff Schott CS590L Spring 2004. What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance

Sample Code

Page 17: Façade Pattern Jeff Schott CS590L Spring 2004. What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance

Related Patterns

Abstract Factory Mediator Singleton Adapter Decorator

Page 18: Façade Pattern Jeff Schott CS590L Spring 2004. What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance

Questions?