文档介绍:EMBEDDED SYSTEMS
PROGRAMMING 2012-13
Design Patterns
DEFINITION
Design pattern: solution to a recurring problem
Describes the key elements of the problem and the
solution in an abstract way
Applicable outside the realm of software
design, but of course software design is what we
will consider in this course
DESIGN PATTERNS
Design patterns capture solutions that
have been developed over time, so
they are not obvious, and
often they are a bit harder than first-thought or
ad-hoc solutions, but
they have proved good many times, hence
they will (probably) pay off in the long term
ELEMENTS OF A DESIGN
PATTERN
Name: makes the pattern recognizable
Problem description (with context)
Solution: describes the key elements to solve the
problem, and the relations between them. DPs for
OO software design may talk about classes and such
Consequences: pros, cons and tradeoffs of applying
the pattern
DESIGN PATTERNS FOR OO
SOFTWARE: CLASSIFICATION
Behavioral patterns: discuss algorithms and
communication paths to manage the information flow
within a system
Creational patterns: aim at making a design
independent of how its objects are created,
composed and represented
Structural patterns: show how pose a large
structure out of simpler ones
WHAT WE WILL SEE
DPs enforced by iOS
Behavioral: Delegation, Target-Action
Structural: Model-View-Controller
Other DPs
Behavioral: Command, Mediator, Observer
Creational: Builder, Singleton
Structural: Composite, Façade, Proxy
NOTATION (1/2)
Class
Class Inheritance
Method()
Variable Pseudocode BaseClass
for(...)
{
/* ... */
Abstract class }
AbstClass SubClass
Method()
Variable
NOTATION (2/2)
“Is part of”
Drawing Shape
“Is an aggregation of”
“Uses”
Server Receiver
“Keeps a reference to”
“Creates”
Calc Matrix
“Instantiates”
DELEGATION
Problem: how to plex objects
without subclassing them
Solution:
custom code for the new beha