L18 Analysis&Design
L18 Analysis&Design
SOFTWARE ENGINEERING
LECTURE 21
SYSTEM ANALYSIS AND DESIGN
Concurrency Structural
Proxy
Active object Balking Decorator
Façade
Read write lock
Bridge Composite
Monitor object Reactor
Flyweight Adapter
Thread pool Scheduler
Calendar Sprinkler
onEvent() { onEvent() {
checkDayOfWeek() checkCalendar()
Calendar
doSprinkler() Sprinkler checkShower()
doCoffeePot() checkTemp()
doAlarm() checkWeather()
// do more stuff // do more stuff
} }
HouseOfTheFuture's dilemma???
Limits Subclassing: Only need to extend the mediator class when the
logic needs to be extended.
Disadvantages
Complexity: The Mediator object can become overly complex.
Concurrency Structural
Proxy
Active object Balking Decorator
Façade
Read write lock
Bridge Composite
Monitor object Reactor
Flyweight Adapter
Thread pool Scheduler
PROXY PATTERN
Problem
We don’t open the multimedia content until we really want to see the content
Sometimes we want to defer the full cost of creating and initializing an object
until we actually need to use it.
Example
realSubject
RealSubject defines RealSubject Proxy
the real object that
Proxy represents. request() request() realSubject → request();
.. ..
. .
Concurrency Structural
Proxy
Active object Balking Decorator
Façade
Read write lock
Bridge Composite
Monitor object Reactor
Flyweight Adapter
Thread pool Scheduler
BRIDGE PATTERN
假设我们有different windows under different OS
Problem: When an abstraction can have several possible
implementations, inheritance is usually used to handle
this. However, this binds an implementation to an
abstraction permanently making it difficult to modify,
extend and reuse abstractions and implementations
independently.
E.g., implementation of a portable Window abstraction in a
user interface toolkit.
«interface» «interface»
Window Window
drawText() devDrawText()
drawRect() devDrawLine()
Concurrency Structural
Proxy
Active object Balking Decorator
Façade
Read write lock
Bridge Composite
Monitor object Reactor
Flyweight Adapter
Thread pool Scheduler
Concurrency Structural
Proxy
Active object Balking Decorator
Façade
Read write lock
Bridge Composite
Monitor object Reactor
Flyweight Adapter
Thread pool Scheduler
Design Principle
Classes should be open for extension,
but closed for modification.
Pizza orderPizza() {
Pizza pizza = new Pizza();
pizza.prepare();
pizza.bake();
pizza.cut();
pizza.box();
We want to be able to make different types
return pizza; of pizza.
}
So, for flexibility, we really want this to be
an abstract class or interface, but we
cannot directly instantiate either of those.
pizza.prepare();
Once we have a Pizza, we prepare it (you know, roll
pizza.bake(); the dough, put on the sauce and add the toppings &
pizza.cut(); cheese), then we bake it, cut it and box it!
pizza.box(); Each Pizza subtype (CheesePizza, GreekPizza, etc.
return pizza; knows how to prepare itself.
}
Bottom Line
The software has reached a point of diminishing returns
where the effort involved to maintain existing code exceeds
the cost of developing a new “ground up” solution.
A nightmare to maintain
(changes or bug fixes
introduce new bugs).
Lost OO advantage.
Unnecessary code
Expensive to load.
Class Analysis
– Structures the system by partitioning use cases into boundary,
control and entity classes.
– Assigns responsibilities to classes.
Class Design
– Completes the specification of each class (attributes, operations).
– Restructures and optimizes classes.
– Makes use of design patterns to handle commonly occurring design
requirements, particularly nonfunctional requirements.