Академический Документы
Профессиональный Документы
Культура Документы
Overview
Books Design Patterns Basics Creational Design Patterns Structural Design Patterns Behavioral Design Patterns
Book
Design Patterns : Elements of Reusable Object-Oriented Software (1995) (The-Gang-of-Four Book) The-Gang-of-Four (GoF) - Gamma, Helm, Johnson , Vlissides
Life Challenges
Software Design!!!
Design Patterns
Each pattern describes
a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice.
---
This was in describing patterns in buildings and towns. In SE, design patterns are in terms of objects and interfaces, not walls and doors.
The manner in which a collection of interacting objects collaborate to accomplish a specific task or provide some specific functionality.
client-server based on remote procedure calls abstraction layering distributed object-oriented system based on CORBA
Defines the system in terms of computational components & their interactions Lower level than architectures (Sometimes, called micro-architecture) Reusable collaborations that solve subproblems within an application
Design Patterns
Design patterns support object-oriented reuse at a high level of abstraction Design patterns provide a framework that guides and constrains object-oriented implementation
Name: identifies a pattern Problem: describes when to apply the pattern in terms of the problem and context Solution: describes elements that make up the design, their relationships, responsibilities, and collaborations Consequences: results and trade-offs of applying the pattern
Model: the application object View: its screen presentation Controller : defines the way the user interface reacts to user input MVC decouples views and models by establishing a subscribe/notify protocol between them
By Purpose (reflects what a pattern does): Creational Patterns Structural Patterns Behavioral Patterns By Scope: specifies whether the pattern applies primarily to classes or to
objects.
10
Creational
Scope Class Object
Factory Method Abstract Factory Builder Prototype Singleton
Behavioral
Interpreter Template Chain of Responsibility Command Iterator Mediator Memento Observer State Strategy Visitor
11
12
13
Software Design
Big problems in practice Big opportunities in research
Have Fun!!
Why modularization?
What is a Modularization?
Making design decisions before the work on independent modules can begin. Quite different decisions are included for each alternative In all cases, the intention is to describe all "system level" decisions (i.e. decisions which affect more than one module).
A Canonical Topic
A Canonical Example
Key Word in Context [Parnas72]
The KWIC index system accepts an ordered set of lines, each line is an ordered set of words, and each word is an ordered set of characters. Any line may be "circularly shifted" by repeatedly removing the first word and appending it at the end of the line. The KWIC index system outputs a listing of all circular shifts of all lines in alphabetical order.
A Canonical Example
Key Word in Context [Parnas72]
1. 2. 3. 4.
Software Architecture Sense and Sensibility Crouching Tiger Hidden Dragon Architecture Software and Sensibility Sense Sensibility Sense and Tiger Hidden Dragon Crouching Hidden Dragon Crouching Tiger Dragon Crouching Tiger Hidden
How should such a system be designed? Modularized? What are the factors to consider?
2. Relations
1. Plain English
Main Program/Subroutine
Module1: Input
This module reads the data lines from the input medium and stores them in core for processing by the remaining modules. The characters are packed four to a word, and an otherwise unused character is used to indicate the end of a word. An index is kept to show the starting address of each line.
Characters
Line Index
Input Medium
Characters
Line Index
Shifts Index
Input Medium
Module 3: Alphabetizing
This module takes as input the arrays produced by modules 1 and 2. It produces an array in the same format as that produced by module 2. In this case, however, the circular shifts are listed in another order (alphabetically).
Input
Circular Shifter
Alphabetizer
Characters
Line Index
Shifts Index
Input Medium
Module 4: Output
Using the arrays produced by module 3 and module 1, this module produces a nicely formatted output listing all of the circular shifts. In a sophisticated system the actual start of each line will be marked, pointers to further information may be inserted, and the start of the circular shift may actually not be the first word in the line, etc.
Input
Circular Shifter
Alphabetizer
Output
Characters
Line Index
Shifts Index
Input Medium
Output Medium
What if:
Memory Size change? Input Size change? Input Format change? Alphabetizing Policy change?
large jobs it may prove inconvenient or impractical to keep all of the lines in core at any one time.
All Modules!!!
3. The decision to pack the characters four to a word. In cases where we are working with small amounts of data it may prove undesirable to pack the characters; time will be saved by a character per word layout. In other cases we may pack, but in different formats.
All Modules!!!
rather than actually store them as such. Again, for a small index or a large core, writing them out may be the preferable approach.
Module 2, 3
5. The decision to alphabetize the list once, rather than either (a) search for each item when needed, or (b) partially alphabetize as is done in Hoare's FIND [2]. In a number of circumstances it would be advantageous to distribute the computation involved in alphabetization over the time required to produce the index. .
Module 3
In Summary
A Canonical Example Describe its Architecture Evaluate its Changeability
Data Abstraction
Elements
Relations
Parnass Modularization 2
Module Module Module Module Module Module
1: 2: 3: 4: 5: 6:
1. 2. 3.
Read module description Identify architecture elements and relations Analyze changeability
Build OO Architecture
Module 1: Line Storage
Public Interface addWord getWord addLine getLine Modules (Objects) 1.LineStorage
Module 2: Input
This module reads the original lines from the input media and calls the line storage module to have them stored internally.
Build OO Architecture
Module 2: Input
2. Input System I/O
Public Interface
1.LineStorage
Build OO Architecture
Module 3: Circular Shifter
2. Input
addWord
getWord
Input Medium
addLine
1. LineStorage
getLine
getLine
3. Circular Shifter
setup
Module 4: Alphabetizer
This module consists principally of two functions. One, ALPH, must be called before the other will have a defined value. The second, ITH, will serve as an index. ITH(i) will give the index of the circular shift which comes ith in the alphabetical ordering.
Build OO Architecture
Module 4: Alphabetizer
2. Input
addWord
getWord
Input Medium
addLine
1. LineStorage
getLine
getLine
getLine
Alpha
setup
3. Circular Shifter
4. Alphabetizer
Module 5: Output
This module will give the desired printing of set of lines or circular shifts.
Build OO Architecture
Module 5: Output
2. Input 5. Output
addWord
getWord
Input Medium
addLine
1. LineStorage
getLine
getLine
getLine
Alpha
setup
3. Circular Shifter
4.Alphabetizer
Output Medium
Build OO Architecture
Module 6: Master Control
What if:
Memory Size change? Input Size change? Input Format change? Alphabetizing Policy change?
core. For large jobs it may prove inconvenient or impractical to keep all of the lines in core at any one time.
LineStorage Module
3. The decision to pack the characters four to a word. In cases where we are working with small amounts of data it may prove undesirable to pack the characters; time will be saved by a character per word layout. In other cases we may pack, but in different formats.
LineStorage Module
circular shifts rather that actually store them as such. Again, for a small index or a large core, writing them out may be the preferable approach.
Circular Shift Module
Changes
1. Input Format
Affected Modules
Input
A much better choice than the main program/subroutine style under these changes!!
Architecture
UML
Class diagram
Describes how modules from the original architectural solution map onto classes. Depicts all classes from the system we are implementing. For each class it depicts its public interface, i.e., public methods that we may invoke to manipulate instances of that class. For each class it depicts its instance variables. Shows how classes relate to each other. Class relations are represented with so-called associations, their type and attributes.
Each module one class. Public interfacethe bottom sub-box, as a list of method declarations.
Class Relations
A directed association: the originating class has as an instance variable an object of the associated class. For example, the Alphabetizer class has an association with the CircularShift class.
Describe how group of objects collaborate to execute a certain task in a running program. Describes the time sequence of method invocations on the run-time:
Objects are shown as boxes at the top of the diagram. Time is represented with the so-called object's lifeline. Method invocation is symbolized through a horizontal line connecting two vertical object's lifelines. Conditions for method invocation and iterative method invocations may be symbolized with special signs.
Creating an object by specifying a class explicitly Dependence on specific operations Dependence on hardware and software platform Dependence on object representations or implementations Algorithmic dependencies Tight coupling Extending functionality by subclassing Inability to alter classes conveniently
71