Object Design Flashcards
What is the purpose of Object Design?
- prepare for implementation of the system model based on design decisions
- optimize system model
- investigate alternative ways to implement system models following design goals
- Serves as basis of implementation
What are the 4 main activities in object design?
• Reuse: identification of existing solutions, use of inheritance, off-the shelf components & additional solution objects, design patterns, open source
• Interface specification: describes precisely each class interface
• Object model restructuring: transforms object design model to improve its
understandability & extensibility
• Object model optimization: transforms object design model to address performance criteria
such as response time or memory utilization
What is the difference between Generalisation and Specialisation? Shortly describe each.
• Generalisation: discovery of inheritance association btw. two classes, where the sub class is discovered first, often occurs in o Biology: first we find individual animals (e.g. elephant, lion, tiger), then we discover common properties among those animals and give them a name (e.g. mammal) o Engineering: inventory on the machines produced by two companies that were recently merged, then define common interface to be shared by all machines
• Specialisation: discovery of inheritance association btw. two classes, where the super class is discovered first
What is a Design Pattern?
Pattern: describes a problem which occurs over and over again in our environment & then describes the core of the solution to solve the problem in a way that you can use this solution a million times over, without ever doing it the same way twice.
Name and shortly describe the 3 types of Design patterns.
Structural patterns: • reduce coupling btw. one or more classes • introduce an abstract class to enable extensions • Encapsulate complex structures
Behavioral patterns:
• Allow choices btw. algorithms
• Allow assignment of responsibilities to objects
• Model complex control flows
Creational patterns:
• Allow to abstract from complex instantiation processes
• Make the system independent from the way its objects are created, composed &
represented
Composite Pattern: What problem does it solve and how does it do so?
Problem: There are hierarchies with arbitrary depth and width (e.g. folders and files)
Solution: Individual Classes called Leafs and Composite inherit from a Component Class. Composite class can have multiple Components as children
Bridge Pattern: What problem does it solve and how does it do so?
Problem: Many design decisions are made final at design time or at compile time
Solution: The bridge pattern allows to delay the binding between an interface and its subclass to the startup time of the system
Proxy Pattern: What problems does it solve and how does it do so? Name at least 1 problem (out of 2)
- Problem #1: The object is complex, its instantiation is expensive
- Solution: Delay the instantiation until the object is actually used & If the object is never used, then the costs for its instantiation do not occur
- Problem #2: The object is located on another node (i.e on a web server), accessing the object is expensive
- Solution: Instantiate and initialize a “smaller” local object, which acts as a representative (“proxy”) for the remote object & Instantiate and initialize a “smaller” local object, which acts as a representative (“proxy”) for the remote object & Access the remote object only if really necessary
Adapter Pattern: What problem does it solve and how does it do so?
Problem: An old “outdated” legacy system is being used but is irreplaceable
Solution: The adapter pattern connects incompatible components and allows the reuse of the system
Observer Pattern: What problem does it solve and how does it do so?
Problem: An object that changes its state often and/or Multiple views of the current state
Solution:
- model a 1-to-many dependency between objects
- Connect the state of an observed object, the subject with many observing objects, the observers
Strategy Pattern: What problem does it solve and how does it do so?
Problem: Different algorithms exist for a specific task
Solution: The strategy pattern allows to switch between different algorithms at run time based on the context and a policy