chapter 8 object design reuse and patterns. object design object design is the process of adding...
TRANSCRIPT
![Page 1: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/1.jpg)
Chapter 8Object Design
Reuse and Patterns
![Page 2: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/2.jpg)
Object Design
• Object design is the process of adding details to the requirements analysis and making implementation decisions
• The object designer must choose among different ways to implement the analysis model with the goal to minimize execution time, memory and other measures of cost.
![Page 3: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/3.jpg)
• Requirements Analysis: Use cases, functional and dynamic model deliver operations for object model
• Object Design: Iterates on the models, in particular the object model and refine the models
• Object Design serves as the basis of implementation
![Page 4: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/4.jpg)
Object Design Activities • Identification of existing components
• Full definition of associations
• Full definition of classes
• Specifying the contract for each component
• Choosing algorithms and data structures
• Identifying possibilities of reuse
![Page 5: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/5.jpg)
• Detection of solution-domain classes
• Optimization
• Increase of inheritance
• Decision on control
![Page 6: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/6.jpg)
First part of object design
• Reuse Concepts
• The use of inheritance
• Implementation vs Interface Inheritance
• Delegation
• Components
![Page 7: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/7.jpg)
Reuse Concepts
• Application objects versus solution objects
• Specification inheritance and implementation inheritance
• The Liskov Substitution Principle
• Delegation
• Delegation and inheritance in design patterns
![Page 8: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/8.jpg)
Application domain vs solution domain objects
• Application objects, also called domain objects, represent concepts of the domain that are relevant to the system.– They are identified by the application domain
specialists and by the end users.
• Solution objects represent concepts that do not have a counterpart in the application domain,– They are identified by the developers– Examples: Persistent data stores, user interface
![Page 9: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/9.jpg)
Implementation of Application Domain Classes
• New objects are often needed during object design:– The use of design patterns introduces new
classes– The implementation of algorithms may
necessitate objects to hold values– New low-level operations may be needed during
the decomposition of high-level operations
![Page 10: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/10.jpg)
Observation about Modeling of the Real World
• [Gamma et al 94]:
• Strict modeling of the real world leads to a system that reflects today’s realities but not necessarily tomorrow’s.
• There is a need for reusable and flexible designs
• Design knowledge complements application domain knowledge and solution domain knowledge.
![Page 11: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/11.jpg)
The use of inheritance
• Inheritance is used to achieve two different goals– Description of Taxonomies– Interface Specification
• Identification of taxonomies– Used during requirements analysis. – Activity: identify application domain objects that are
hierarchically related– Goal: make the analysis model more understandable
![Page 12: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/12.jpg)
• Service specification– Used during object design– Activity: – Goal: increase reusability, enhance
modifiability and extensibility
• Inheritance is found either by specialization or generalization
![Page 13: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/13.jpg)
Metamodel for Inheritance
Inheritance
Specification (Interface)Inheritance
ImplementationInheritance
Inheritancefor ReuseTaxonomy
Inheritance detectedby generalization
Inheritance detectedby specialization
Analysisactivity
Object Design
![Page 14: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/14.jpg)
Taxonomy Example
Mammal
Tiger Wolf Whale
![Page 15: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/15.jpg)
Implementation Inheritance
• A very similar class is already implemented that does almost the same as the desired class implementation.
![Page 16: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/16.jpg)
Problem with implementation inheritance:
Some of the inherited operations might exhibit unwanted behavior. What happens if the Stack user calls Remove() instead of Pop()?
Example: I have a List class, I need a Stack class. How about subclassing the Stack class from the List class and providing three methods, Push() and Pop(), Top()?
Add ()
Remove()
List
Push ()Pop()
Stack
Top()
“Already implemented”
Implementation Inheritance
![Page 17: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/17.jpg)
Implementation Inheritance vs Interface Inheritance
• Implementation inheritance– Also called class inheritance– Goal: Extend an applications’ functionality by
reusing functionality in parent class– Inherit from an existing class with some or all
operations already implemented
![Page 18: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/18.jpg)
• Interface inheritance– Also called subtyping– Inherit from an abstract class with all
operations specified, but not yet implemented
![Page 19: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/19.jpg)
Delegation as alternative to Implementation Inheritance
• Delegation is a way of making composition as powerful for reuse as inheritance
• In Delegation two objects are involved in handling a request– A receiving object delegates operations to its
delegate. – The developer can make sure that the receiving
object does not allow the client to misuse the delegate object
![Page 20: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/20.jpg)
Client Receiver DelegateDelegates to calls
Delegation as alternative to Implementation Inheritance
![Page 21: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/21.jpg)
Delegation instead of Implementation Inheritance
• Inheritance: Extending a Base class by a new operation or overwriting an operation.
• Delegation: Catching an operation and sending it to another object.
• Which of the following models is better for implementing a stack?
![Page 22: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/22.jpg)
Delegation instead of Implementation Inheritance
+Add()+Remove()
List
Stack
+Push()+Pop()+Top()
+Push()+Pop()+Top()
Stack
Add()Remove()
List
![Page 23: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/23.jpg)
Many design patterns use a combination of inheritance and
delegation
Many design patterns use a combination of inheritance and
delegation
Lecture on Design Patterns
![Page 24: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/24.jpg)
Component Selection
• Select existing – off-the-shelf class libraries– frameworks or – components
• Adjust the class libraries, framework or components– Change the API if you have the source code.– Use the adapter or bridge pattern if you don’t have
access
![Page 25: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/25.jpg)
Frameworks
• A framework is a reusable partial application that can be specialized to produce custom applications.
• Frameworks are targeted to particular technologies
• The key benefits of frameworks are reusability and extensibility.
![Page 26: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/26.jpg)
– Reusability leverages of the application domain knowledge and prior effort of experienced developers
– Extensibility is provided by hook methods, which are overwritten by the application to extend the framework.
• Hook methods systematically decouple the interfaces and behaviors of an application domain from the variations required by an application in a particular context.
![Page 27: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/27.jpg)
White-box and Black-Box Frameworks
• Whitebox frameworks:– Extensibility achieved through inheritance – Existing functionality is extended by
subclassing framework base classes and overriding predefined hook methods
![Page 28: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/28.jpg)
• Blackbox frameworks – Extensibility achieved by defining interfaces
for components that can be plugged into the framework.
– Existing functionality is reused by defining components that conform to a particular interface
– These components are integrated with the framework via delegation.
![Page 29: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/29.jpg)
Class Libraries and Frameworks
• Class Libraries: – Less domain specific
– Provide a smaller scope of reuse.
– Class libraries are passive; no constraint on control flow.
• Framework: – Classes cooperate for a family of related applications.
– Frameworks are active; affect the flow of control.
![Page 30: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/30.jpg)
• In practice, developers often use both:– Frameworks often use class libraries internally
to simplify the development of the framework. – Framework event handlers use class libraries to
perform basic tasks (e.g. string processing, file management, numerical analysis…. )
![Page 31: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/31.jpg)
Reuse
• Main goal: – Reuse knowledge from previous experience to
current problem– Reuse functionality already available
• Composition (also called Black Box Reuse)– New functionality is obtained by aggregation– The new object with more functionality is an
aggregation of existing components
![Page 32: Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation](https://reader036.vdocuments.mx/reader036/viewer/2022081501/56649f0d5503460f94c21b64/html5/thumbnails/32.jpg)
• Inheritance (also called White-box Reuse)– New functionality is obtained by inheritance.
• Three ways to get new functionality: • Implementation inheritance
• Interface inheritance
• Delegation