+ All Categories
Home > Documents > Lecture 27: Façade Pattern

Lecture 27: Façade Pattern

Date post: 06-Feb-2016
Category:
Upload: harry
View: 28 times
Download: 0 times
Share this document with a friend
Description:
Computer Science 313 – Advanced Programming Topics. Lecture 27: Façade Pattern. “In a Nutshell”. Commonly used English expression Means “in a few words” or “briefly” Summarizing idea with many details left out. “In a Nutshell”. - PowerPoint PPT Presentation
Popular Tags:
19
LECTURE 27: FAÇADE PATTERN Computer Science 313 – Advanced Programming Topics
Transcript
Page 1: Lecture 27: Façade Pattern

LECTURE 27:FAÇADE PATTERN

Computer Science 313 – Advanced Programming Topics

Page 2: Lecture 27: Façade Pattern

“In a Nutshell”

Commonly used English expression Means “in a few words” or “briefly” Summarizing idea with many details left

out

Page 3: Lecture 27: Façade Pattern

“In a Nutshell”

Commonly used English expression Means “in a few words” or “briefly” Summarizing idea with many details left

out

I could be bounded in a nutshell, and count

my selfe a King of infinite space.

Page 4: Lecture 27: Façade Pattern

nutshell.flv“In a Nutshell”

Usage can be traced back to 1608 Even before Hamlet used it

Meaning has not changed in 400 years Also became a verb in that time “To nutshell” popularized by Mark Twain

Any questions about what it means?

Page 5: Lecture 27: Façade Pattern

“In a Nutshell”

Usage can be traced back to 1608 Even before Hamlet used it

Meaning has not changed in 400 years Also became a verb in that time “To nutshell” popularized by Mark Twain

Any questions about what it means? WILL SOMEONE EXPLAIN THIS TO

O’REILLY!

Page 6: Lecture 27: Façade Pattern

Big Picture for Façade

Provide simple interface to low-level functions Create single class defining simple

methods May combine functionality of multiple

instances Façade makes client easier to write &

use Packages tricky parts into simple

method(s) Allows client to avoid working with many

instances Nothing should change in lower level

classes Using the façade complex subsystem

hidden But still usable without going through

façade

Page 7: Lecture 27: Façade Pattern

Real-Life is Hard

Real life is full of complex ideas & concepts Filling out your tax forms every April Rules for holding in (American) football Explaining why the sky is blue Appeal of soccer to billions worldwide

Page 8: Lecture 27: Façade Pattern

Real-Life is Hard

Often rely on simplicities to understand these Filling out your tax forms every April

“Politician got bribe contribution to create deduction”

Rules for holding in (American) football “Stay within the shoulder pads & don’t get caught”

Explaining why the sky is blue“Wavelengths not scattered by the atmosphere”

Appeal of soccer to billions worldwide“Excuse to drink beer & occasionally riot”

Page 9: Lecture 27: Façade Pattern

Real-Life Façade

Compiler is (real-life) example of façade Typically we think of compiler as single

system Many complex systems combine to make

compiler Code divided into tokens by the parser Lexigraphical analyzer computes tokens’

meanings Analysis improved & simplified by optimizer Code generator lowers & outputs result

Even so, many of these systems also façades: Loop analyzer, SSA transform, peepholer in

optimizer

Page 10: Lecture 27: Façade Pattern

Façades On Computers

Page 11: Lecture 27: Façade Pattern

Façade We Regularly Use

Usually do all interactions via simple interface javac foo.java compiles class named foo

But can also access components directly final & volatile provide details to

optimizer Can get instance of javax.tools.JavaCompiler

Page 12: Lecture 27: Façade Pattern

Façade We Regularly Use

Compilation easy because of this façade Façade simplifies & allows messing with

internals All skill levels helped using the

compiler Beginnerjavac foo.java

Expertjavac –g:none foo.java

Stupidjavac –nowarn –Xprint foo.java

Page 13: Lecture 27: Façade Pattern

Façade versus Adapter

Façade and Adapter patterns very similar Enable simplifying code to be used by

client Both patterns effectively hide subsystem

details 1 or more instances behind exposed

interface Idealized UML class diagram may/may

not differ “What is the difference?” should be

asked

Page 14: Lecture 27: Façade Pattern

Intent Crucial to Usage

Adapter makes existing code use interface Original implementation hidden by pattern Lets client code think class written for

interface Adapts existing code so it can work in other

places Façade used to create interface to use

system Original implementation hidden by pattern Lets client write code as if design has simple

interface Provides a false front for use in another

system

Page 15: Lecture 27: Façade Pattern

Clients of Façade & Adapter With either pattern within client

code:

No difference in usage

No difference in design

Page 16: Lecture 27: Façade Pattern

Using Façade & Adapter

Façade Adapter

Yams

\

Sweet Potatoes

Page 17: Lecture 27: Façade Pattern

Using Façade & Adapter

Façade Adapter

Yams

Sweet Potatoes

\

Sweet Potatoes

Yams

Page 18: Lecture 27: Façade Pattern

Kissing Cousins of Patterns Adapter & Façade also close to

Decorator Structural patterns that help simplify

client code Within each pattern, hide

implementation details Workings invisible to those outside

pattern Decorator has some important

differences Decorations invisible; adapter & façade

not Decorator requires specific class

relationships Interface unchanged by decorator

pattern

Page 19: Lecture 27: Façade Pattern

For Next Class

Lab #6 due in one week Do not leave labs to last second

Read pages 265 – 275 for Friday What is the Principle of Least Knowledge? How much of class already follows this

principle? What is the Law of Demeter? Can we quantify this principle?


Recommended