Professional Documents
Culture Documents
Michel Chaudron
Agenda
Design guidelines
Architectural Styles
MRV Chaudron
Sheet 2
design:
The division into subsystems and components, How these will be connected: How they will interact: Interface design & architectural style
Class
design:
User
design:
MRV Chaudron
Sheet 3
Sheet 4
You will make mistakes, but you should learn from them
There is no objective measure for goodness
MRV Chaudron
Sheet 5
Churchman, C. West, "Wicked Problems", Management Science, Vol. 14, No. 4, December 1967. Guest Editorial
Design Metrics
Synthesize
UML, Views
MRV Chaudron
Design Principles
Simplicity Separation of Concerns Information Hiding Modularity Keep things that belong together in a single place
How to assess?
MRV Chaudron Sheet 8
David Parnas
We propose that one begins with a list of difficult design decisions or design decisions which are likely to change. Each module is then designed to hide such a decision from the others.
The KWIC [Key Word in Context] 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.
D. L. Parnas, On the criteria to be used in decomposing systems into modules, Communications of the ACM, vol. 15, pp. 1053-1058, Dec.1972.
Parnas shows that different problem decompositions vary greatly in their ability to withstand design changes. Among the changes he considers are:
Changes in processing algorithm: For example, line shifting can be performed on each line as it is read from the input device, on all the lines after they are read, or on demand when the alphabetization requires a new set of shifted lines.
Changes in data representation: For example, lines can be stored in various ways. Similarly, circular shifts can be stored explicitly or implicitly (as pairs of index and offset).
KWIC example
Message: there are many different solutions for the same set of requirements
17
Not all boxes in a design are the same thing Not all arrows in a design are the same thing Imprecision in communication about these boxes and arrows can add significant confusion to a software design process and the resulting design Oh, thats the issue of clarity again
18
Separate interfaces from implementations Implementations capture decisions likely to change Interfaces capture decisions unlikely to change Clients know only interface, not implementation Implementations know only interface, not clients
19
Information hiding
each module has a secret design involves a series of decision: for each such decision, wonder who needs to know and who can be kept in the dark information hiding is strongly related to
abstraction: if you hide something, the user may abstract from that fact coupling: the secret decreases coupling between a module and its environment cohesion: the secret is what binds the parts of the module together
www.wileyeurope.com/college/van vliet 20
Faade pattern
Client classes
Faade
Sheet 21
21
Separation of Concerns
The interface of a component exposes what function it can perform, not how. The how is the information-hiding secret
22
decode1 ; decode2 ; decode3 ; action1 ; action2 decode1 ; action1 ; decode2 ; action2 ; decode3
And not
MRV Chaudron
Sheet 23
Trying to deal with something big all at once is normally much harder than dealing with a set of smaller things
Each
individual component is smaller, and therefore easier to understand can be replaced or changed without having to replace or extensively change other parts. people can work on separate parts individual software engineer can specialize
24
Parts
Separate An
MRV Chaudron
Sheet 24
& subsystems
subsystem can be divided package is divided up into classes class is divided up into methods
MRV Chaudron
Sheet 25
25
Layering
Goals: Separation of Concerns, Abstraction, Modularity, Portability Partitioning in non-overlapping units that
- provide a cohesive set of services at an abstraction level (while abstracting from their implementation) - layer n is allowed to use services of layer n-1 (and not vice versa) alternative: bridging layers: layer n may use layers <n enhances efficiency but hampers portability
MRV Chaudron
3 2 1 0
Sheet 26
26
MRV Chaudron
Sheet 27
27
Sheet 28
28
client
Business logic
Logic for processing across users, divisions Data management Storage of data
MRV Chaudron
server
Sheet 29
30
Network
Data Link Physical
Picture from Jeremy Bradbury, Queens Univ. Canada
MRV Chaudron
Sheet 31
31
specific generic
MRV Chaudron
Sheet 33
33
What is Modularity?
MRV Chaudron
Sheet 36
36
What is a dependency?
coupling
Run-time
MRV Chaudron
Sheet 37
37
Sheet 38
38
Dependency: Coupling
Coupling is the degree of interdependence between modules
high coupling
low coupling
Sheet 39
39
time needed for understanding the modules and interactions the chance that changes in one module cause problems in other modules, which enhances
reusability
the chance that a fault in one module will cause a failure in other modules, which enhances
robustness
Page-Jones, M. 1980. The Practical Guide to Structured Systems Design. New York, Yourdon Press, 1980.
MRV Chaudron
Sheet 40
40
Coupling Saat 7
Dynamic Coupling 10
Method Calls 25
Stat.-Filter
Stat.Calculator Analyser DB-Checker DB-Filler DB-Creator
0
0 0 0 0 0
3
3 4 2 5 2
0
0 0 0 0 0
Parser
MRV Chaudron
3
42
Sheet 42
Method Calls
2 1 0 12 0 10 0 0
43
Stat.Calculator
Analyser DB-Checker DB-Filler DB-Creator Parser
MRV Chaudron
Sheet 43
MetricView video
http://www.win.tue.nl/empanada/metricview/
http://www.youtube.com/watch?v=G3HJ_QR9EG4
Sheet 46
46
Dependency: Cohesion
Cohesion is concerned with the interactions within a module
high cohesion
low cohesion
Heuristic:
Keep things together that belong together. High cohesion within a module is good
Coupling is the degree of interaction between modules. Cohesion is a measure of the coherence of a module amongst the pieces of that module.
49
MRV Chaudron
Sheet 50
50
Faade pattern
Client classes
Faade
Sheet 51
51
Facade pattern
Bedoeling
Verschaf een uniforme interface tot een (verzameling interfaces van een) subsysteem
Motivatie
Subsystemen reduceren de complexiteit Belangrijk ontwerpdoel: minimaliseren van de communicatie en afhankelijkheden tussen subsystemen Eenvoudige, uniforme interface tot subsysteem is wenselijk Individuele interfaces moeten beschikbaar blijven
Types of Coupling
Data coupling
data from one module is used in another two modules use the same data type
Control coupling
actions one module are controlled by another module (switch)
considered worse
Content coupling
Sheet 55
55
When two classes collaborate frequently, this is an indication they should be in the same domain component to reduce the network traffic between the two classes. This is especially true when that interaction involves large objects, either passed as parameters or received as return values. By including them in the same domain component you reduce the potential network traffic between them. The basic idea is that highly coupled classes belong together.
56
Client/server classes belong in a domain component, but there may be a choice as to which domain component they belong to. This is where you need to consider issues such as the information flow going into and out of the class. Communication within a component will often be simple message sends between objects in memory, communication between components may require an expensive marshalling effort in which a message and its parameters are converted to data, transmitted, and then converted back into a message again.
From Scott Ambler
MRV Chaudron Sheet 57
57
Main Board
x x x x
x x x x x x . x x x x . x x x x x x . x x x x x . x x x x . x x x x . x x x x . x x x x x x x x x . x
x . x x x x x x x . x x x x x x . x x x x x . x x x x x x x x x . x x x x . x x x
x x x x Packaging
x x
x x x x x x x
Graphics controller on Main Board or not? If yes, screen specifications change; If no, CPU must process more; adopt different interrupt protocols
MRV Chaudron
Sheet 58
58
Drive System
. x x x x
x . x x
x x . x x x x
x x x x . x x . x x x . . x . x x x x x x x x x . x x x x x x x . x x . x x x . x x x x x x x x x x . x x .
LCD Screen
. x x x x . x x x x . x x x x . x x x x x . x x x x . . x x x x x x x x x . x x x . x x x . x x x x . x x x x . x x x x x x . x x x x x x x . x x x x x x
P ackaging
x x x x x
x x x x x x
x x x x x x
x x x x x x
. x x x x x
x x x . x x x . x x x x x x x . x x
MRV Chaudron
Sheet 59
59
Formerly Mozilla was the commercial Netscape Navigator, then released into open source.
From: Exploring the Structure of Complex Software Designs: An Empirical Study of Open Source and Proprietary Code, Alan MacCormack, John Rusnak, Carliss Baldwin, MRV Chaudron Sheet 60 Harvard Business School, draft October 1st 2005
60
Conclusions
Information Hiding
Low Coupling, High Cohesion Layering, Modularity
61
9.9 Difficulties and Risks in Design Like modelling, design is a skill that requires considerable experience
Individual software engineers should not attempt the design of large systems Aspiring software architects should actively study designs of other systems
MRV Chaudron
Sheet 62
It requires constant effort to ensure a software systems design remains good throughout its life
Make the original design as flexible as possible so as to anticipate changes and extensions. Ensure that the design documentation is usable and at the correct level of detail Ensure that change is carefully managed
MRV Chaudron
Sheet 63
63
The two most common techniques for reusing functionality in object-oriented systems are class inheritance and object composition Class inheritance defines the implementation of one class in terms of anothers implementation. With inheritance the internals of parent classes are often visible to sub-classes (white box). In object composition new functionality is obtained by assembling or composing objects to get more complex functionality. Internal details of objects are not visible, objects appear as black boxes.
MRV Chaudron
Sheet 64
64
Pros: Class inheritance is defined statically at compile-time and is straightforward to use, since its supported directly by the programming language. Class inheritance makes it easier to modify the implementation being reused. Cons: You can not change the implementations being inherited at run-time. Inheritance exposes as subclass to details of its parents implementation. Any change in the parents implementation will force the subclass to change. One cure is to only inherit from abstract classes since they provide little or no implementation.
MRV Chaudron
Sheet 65
65
Composition is defined at run-time through objects acquiring references to other objects. Composition requires objects to respect each others interface. Because objects are accessed solely through their interfaces we dont break encapsulation. Any object can be replaced at run-time by another as long as it has the same type. Because an objects implementation is written in terms ob object interfaces, there are substantially fewer implementation dependencies.
MRV Chaudron
Sheet 66
66
Favoring object composition over class inheritance helps you keep each class encapsulated and focused on one task. Classes and class hierarchies remain small and managable. A design based on object composition has more objects (if fewer classes) and the system behavior depends on their interrelationships instead of being defined in one class.
MRV Chaudron
Sheet 67
67
Assigning Responsibilities
>
>
>
Lethbridge/Laganire 2005
ESE 4.68
>
>
Lethbridge/Laganire 2005
ESE 4.69
Characterizing Classes
according to Rebecca J. Wirfs-Brock, IEEE Software, March/April 2006 Information holder: an object designed to know certain information and provide that information to other objects.
Structurer: an object that maintains relationships between objects and information about those relationships. Complex structurers might pool, collect, and maintain groups of many objects; simpler structurers maintain relationships between a few objects. An example of a generic structurer is a Java HashMap, which relates keys to values.
Service provider: an object that performs specific work and offers services to others on demand. Controller: an object designed to make decisions and control a complex task.
Coordinator: an object that doesnt make many decisions but, in a rote or mechanical way, delegates work to other objects. The Mediator pattern is one example.
Interfacer: an object that transforms information or requests between distinct parts of a system. The edges of an application contain user-interfacer objects that interact with the user and external interfacer objects, which communicate with external systems. Interfacers also exist between subsystems. The Facade pattern is an example of a class designed to simplify interactions and limit clients visibility of objects within a subsystem. Lethbridge/Laganire 2005 ESE 4.70
Aspect Orientation
www.wirfs-brock.com
Copyright 2000
73
73
Structure model :, A C B D
Development model
Behaviour model : A B C D
www.wirfs-brock.com
Copyright 2000
74
74