






























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!































Material and some slide content from:
! " # $ !! $ %! ! &
‣ (^) Weather data example (similar to Eclipse example) ‣ (^) WeatherData ‣ (^) temp, humidity, pressure ‣ (^) calls newData() whenever something changes ‣ (^) bad: update views directly from here ‣ (^) WeatherViews ‣ (^) Current View ‣ (^) Forecast View ‣ (^) Stats View
‣ (^) Intent: “Ensure a class has only one instance” ‣ (^) Motivation: For situations when having multiple copies of an object is either unnecessary or incorrect. ‣ (^) Applicability: ‣ (^) Situations when there must be only one copy of a class.
‣ (^) Collaborations ‣ (^) All collaboration via instance operation. ‣ (^) Consequences: ‣ (^) Controlled access to instance. ‣ (^) Reduced name space. ‣ (^) Permits variable number of instances. ‣ (^) More flexible than class operation
‣ (^) Implementation:
‣ (^) Participants: ‣ (^) Client: Calls the adapter; is completely isolated from the adaptee. ‣ (^) Adapter: Forwards calls between client and adapter. The adapter may have to interact with multiple classes. ‣ (^) Adaptee: Component being adapted. ‣ (^) Alternatives: ‣ (^) Both class and object adapters exist. Class adapters use multiple inheritance to be an instance of both objects simultaneously while object adaptors rely on composition.
‣ (^) Intent: “Enable a group of objects to be treated as single object” ‣ (^) Motivation: Differentiating between interior and leaf nodes in tree-structured data data increases system complexity. ‣ (^) Applicability: ‣ (^) If you notice you are treating groups and individual of objects the same way ‣ (^) Can also be used when primitives and objects need to be treated identically
‣ (^) Participants: ‣ (^) Component: base class ‣ (^) Leaf: individual leaf node ‣ (^) Composite: node that maintains a list of children nodes
‣ (^) Intent: “Provide a unified, higher-level, interface to a whole module making it easier to use.” ‣ (^) Motivation: Composing classes into subsystems reduces complexity. Using a Facade minimizes the communication dependencies between subsystems. ‣ (^) Applicability: ‣ (^) When you want a simple interface to a complex subsystem. ‣ (^) There are many dependencies between clients and a subsystem. ‣ (^) You want to layer your subsystems.
‣ (^) Participants: ‣ (^) Facade ‣ (^) Subsystem classes ‣ (^) Collaborations: ‣ (^) Clients interact subsystem via Facade. ‣ (^) Consequences: ‣ (^) Shields clients from subsystem components. ‣ (^) Promotes weak coupling. (strong within subsystem, weak between them) ‣ (^) Doesn’t prevent access to subsystem classes.
‣ (^) Intent: “Define the skeleton of an algorithm deferring some steps to client subclasses” ‣ (^) Motivation: When two algorithms are largely the same but differ in only a few small details the algorithm can be encapsulated in a base class and defer specific functionality to child classes. ‣ (^) Applicability: ‣ (^) Template method implements invariant parts of the algorithm. ‣ (^) Base class contains the majority of functionality, reducing code duplication.
‣ (^) Participants: ‣ (^) Base class, defining common functionality in concrete method making calls to abstract ‘hook’ methods. ‣ (^) Sub classes, overriding subclass-specific parts of the algorithm.