Seoc05 Notes
Seoc05 Notes
Massimo Felici
Massimo Felici
Design Patterns
c 20042011
Massimo Felici
Design Patterns
c 20042011
Massimo Felici
Design Patterns
c 20042011
Massimo Felici
Design Patterns
c 20042011
Massimo Felici
Design Patterns
c 20042011
Key Factors
Planning Reuse
The development schedule for the software The expected software lifetime The background, skills and experience of the development team The criticality of the software and its non-functional requirements The application domain The platform on which the system will run
Massimo Felici
Design Patterns
c 20042011
Types of Reuse
Reuse of Knowledge Artifact reuse Pattern reuse Reuse of Software Code reuse Inheritance reuse Template reuse Component reuse Framework reuse
Massimo Felici
Design Patterns
c 20042011
Reuse of Knowledge
Artifact Reuse
Reuse of use cases, standards, design guidelines, domain-specic knowledge Pluses: consistency between projects, reduced management burden, global comparators of quality and knowledge Minuses: overheads, constraints on innovation (coder versus manager)
Massimo Felici
Design Patterns
c 20042011
Reuse of Knowledge
Pattern Reuse
A design pattern is a solution to a common problem in the design of computer systems Reuse of publicly documented approaches to solving problems (e.g., class diagrams) Plusses: long life-span, applicable beyond current programming languages, applicable beyond Object Orientation? Minuses: no immediate solution, no actual code, knowledge hard to capture/reuse.
Massimo Felici
Design Patterns
c 20042011
Documenting Patterns
Pattern Name Classication Intent Also Known As Motivation (Forces) Applicability Structure Participants Collaborations Consequences Implementation Sample Code Known Uses Related Patterns
Massimo Felici
Design Patterns
c 20042011
10
Builder
Separate the construction of a complex object from its representation so that the same construction process can create dierent representations
Massimo Felici
Design Patterns
c 20042011
11
Factory Method
Dene an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses
Massimo Felici
Design Patterns
c 20042011
12
Adapter
Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldnt otherwise because of incompatible interfaces
Massimo Felici
Design Patterns
c 20042011
13
Composite
Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly
Massimo Felici
Design Patterns
c 20042011
14
Observer
Dene a one to many dependency between objects so that when one object changes state, all its dependents are notied automatically
Massimo Felici
Design Patterns
c 20042011
15
State
Allow an object to alter its behavior when its internal state changes. The object will appear to change its class
Massimo Felici
Design Patterns
c 20042011
16
Massimo Felici
Design Patterns
c 20042011
17
Massimo Felici
Design Patterns
c 20042011
Reuse of Software
18
Code Reuse
Reuse of (visible) source code - code reuse versus code salvage Pluses: reduces written code, reduces development and maintenance costs Minuses: can increase coupling, substantial initial investment
Massimo Felici
Design Patterns
c 20042011
Reuse of Software
19
Inheritance
Using inheritance to reuse code behaviour Pluses: takes advantage of existing behaviour, decrease development time and cost Minuses: can conict with component reuse, can lead to fragile class hierarchy - dicult to maintain and enhance
Massimo Felici
Design Patterns
c 20042011
Reuse of Software
20
Template Reuse
Reuse of common data format/layout (e.g., document templates, web-page templates, etc.) Pluses: increase consistency and quality, decrease data entry time Minuses: needs to be simple, easy to use, consistent among groups
Massimo Felici
Design Patterns
c 20042011
Reuse of Software
21
Component Reuse
Analogy to electronic circuits: software plug-ins Reuse of prebuilt, fully encapsulated components; typically self-sucient and provide only one concept (high cohesion) Pluses: greater scope for reuse, common platforms (e.g., JVM) more widespread, third party component development Minuses: development time, genericity, need large libraries to be useful
Massimo Felici
Design Patterns
c 20042011
Reuse of Software
22
Framework Reuse
Collection of basic functionality of common technical or business domain (generic circuit boards) for components Pluses: can account for 80 Minuses: substantial complexity, leading to long learning process, platform specic, framework compatibility issues leading to vendor specicity, implement easy 80
Massimo Felici
Design Patterns
c 20042011
23
Reuse Pitfalls
Underestimating the diculty of reuse Having or setting unrealistic expectations Not investing in reuse Being too focused on code reuse Generalising after the fact Allowing too many connections
Massimo Felici
Design Patterns
c 20042011
24
Massimo Felici
Design Patterns
c 20042011
25
Readings
Required Readings UML course textbook, Chapter 17 on Design Patterns T. Winn, P. Calder. Is This a Pattern?. IEEE Software 19(1):59-66, January/February, 2002. Suggested Readings E. Gamma, R. Helm, R. Johnson, J. Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, 1995. M. Schumacher, E. Fernandez-Buglioni, D. Hybertson, F. Bushmann, P. Sommerlad. Security Patterns: Integrating Security and Systems Engineering. John Wiley & Sons, 2006.
Massimo Felici Design Patterns c 20042011
26
Summary
Many types of reuse (of both knowledge and software) Each has pluses and minuses Component reuse is a form of software reuse Encapsulation, high cohesion, specied interfaces explicit context dependencies Component development requires signicant time and eort, as does component reuse Component reuse has been successful for interfaces and data handling Employing reuse requires management
Massimo Felici Design Patterns c 20042011