View Source: Design Patterns in the Wild Thinking in Patterns · 2008. 4. 10. · of architectural...

Post on 15-Oct-2020

0 views 0 download

transcript

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

View Source: Design Patterns in the Wild

Thinking in Patterns

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

Someone invented or developed the code that contains the patterns, but that’s largely irrelevant: It’s that the same solution or style has been used and found habitable... Patterns are discovered because they are well-used, they form a vein that anyone could find.

Richard P. Gabriel“Repetition, Generativity and Patterns”

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

Components Data

Connectors

Software ArchitectureA software architecture is defined by a configuration of architectural elements - components, connectors, and data - constrained in their relationships in order to achieve a desired set of architectural properties.

Roy Fielding“Architectural Styles and the Design of Network-based Software Architectures”

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

WWW

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

Client ServerHTTP

● Separation of concerns● Encapsulation of functionality● Standardized interface

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

Facade

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

● On the client:– Arbitrary file types

– Unique handler for each file type

● On the server:– Arbitrary protocols

– Unique handler for each protocol

Client

GIF

XML

HTML

PDF

MP3

Server

HTTP 1.0

HTTP 1.1

Proxy Custom

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

Abstract Factory

Strategy

... or Dependency Injection

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

● Handle many types of images● Render each in a similar fashion

Client

GIF

JPEG

PNG

BMP ServerHTTP

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

Adapter

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

● Render different formats in a single page

... <img src='/images/me.gif'/> ...

<embed type='application/x-shockwave-flash' src='/myapp.swf' /> ...

Client

GIF

Flash

HTML

ServerHTTP

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

Template Method

Visitor

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

Client ServerHTTPCache Cache

● Caching built into HTTP● Maintain standard interface● Cache is an optional feature

ProxyCache

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

Intercepting Filter

Proxy

+ Prevalence for storage

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

Client ServerHTTP

HTML + Javascript

● Execute logic when a HTML page loads

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

Observer

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

Client ServerHTTP

● Javascript generated on server● Sent to client for execution

Javascript

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

Command

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

ClientServer

HTTP

● Broadcast to many interested clients

ClientClient

ClientClient

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

Publish/Subscribe

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

Other Patterns

● Mediator● Prototype● Map/Reduce● Model-View-Controller● Data Access Object, Active Record

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

... and more

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

No Silver Bullet

● Essential Complexity

“difficulties inherent in the nature of software”

● Accidental Complexity

“difficulties that attend to its production ... but are not inherent”

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

Between order and chaos, interesting and unexpected combinations come about and last long enough to have repercussions. Trends can be observed. Patterns emerge.

Richard P. Gabriel and Ron Goldman“Mob Software: The Erotic Life of Code”

Ashwin J Mathew Spring 2008School of Information, UC Berkeley

Whereas the difference between poor conceptual designs and good ones may lie in the soundness of design method, the difference between good designs and great ones surely does not. Great designs come from great designers. Software construction is a creative process.

Fred Brooks “No Silver Bullet: Essence and Accidents of Software Engineering”