1/55
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is the purpose of the Creator pattern?
To assign responsibility for creating instances of a class A to a class B under specific conditions, supporting low coupling and reuse.
List the four conditions that make class B a suitable Creator of class A.
B contains or compositely aggregates A; B records A; B closely uses A; B has the initializing data for A.
Give an example of the Creator pattern from the Monopoly case study.
Board creates Square objects because it aggregates them and has the initializing data (square names).
What are the contraindications for using the Creator pattern?
When object creation is complex (recycled instances, conditional or family-based creation); use Factory or Builder patterns instead.
What problem does the Information Expert pattern solve?
Determines which object should have a responsibility based on where the necessary information resides.
State the Information Expert pattern solution.
Assign a responsibility to object X if X has or can access the information needed to fulfill that responsibility.
Provide an example of Information Expert from the POS system.
SaleLineItem calculates its own subtotal because it has access to quantity and price (via ProductDescription).
What are the contraindications for Information Expert?
When following Expert creates undesirable dependencies (e.g., spreading database logic across domain classes); use Pure Fabrication instead.
What is the goal of the Low Coupling principle?
Minimize dependencies between classes to reduce change impact and improve maintainability and reuse.
Explain the Low Coupling example for Subtotal calculation in POS.
Choosing SaleLineItem over ProductDescription avoids coupling Sale to ProductDescription when totaling subtotals.
What does High Cohesion ensure in class design?
Responsibilities within a class are strongly related, making the class focused, understandable, and maintainable.
Describe the High Cohesion example for payment creation in POS.
Sale creates Payment rather than Register to prevent Register from becoming bloated and maintain cohesive duties.
How do Low Coupling and High Cohesion work together?
They balance each other: low coupling reduces dependencies, high cohesion keeps responsibilities focused; both guide design choices.
Why is responsibility-driven design important in OO modelling?
It aligns software classes and their behaviors with domain concepts, ensuring intuitive and maintainable designs.
Define a software pattern.
A named problem-solution pair based on proven expertise that can be reused in new contexts.
How do patterns improve team communication?
By providing a common vocabulary to explain design decisions and rationale clearly.
What real-world example illustrates the idea of a design pattern?
A bathroom layout pattern includes sink, toilet, and bathtub—a recurring successful solution.
Why should patterns not be applied blindly?
Because each pattern has contraindications and must be weighed against project-specific requirements.
What problem does Indirection solve?
Avoids direct coupling between two (or more) objects by introducing an intermediate mediator.
What is the solution proposed by the Indirection pattern?
Assign the responsibility to an intermediate object that mediates interactions between the dependent and questionable elements.
What is a contraindication of using Indirection?
It can introduce performance overhead in high-performance systems requiring minimal layers of indirection.
In the POS example, which class implements Indirection for tax calculation?
TaxMasterAdapter mediates between Sale and the external TaxMasterSystem.
What problem does Pure Fabrication solve?
Maintains high cohesion and low coupling when no domain class is appropriate for a responsibility.
What is the solution proposed by the Pure Fabrication pattern?
Create an artificial class to hold a cohesive set of responsibilities unrelated to domain concepts.
What is a contraindication of using Pure Fabrication?
Overuse can lead to many tiny classes and excessive coupling between them.
In the Monopoly example, which fabricated class is used for rolling dice?
Cup serves as a fabricated mediator to roll dice and return totals.
What problem does Polymorphism solve?
Eliminates complex conditional logic by varying behavior based on object type, and supports pluggable components.
What is the solution proposed by the Polymorphism pattern?
Define polymorphic operations (same interface) in subclasses to handle type-specific behavior.
What is a contraindication of using Polymorphism?
Applying it speculatively for unlikely future variations can overcomplicate the design.
In the Monopoly example, which operation is polymorphic?
The landedOn() method varies behavior across GoSquare, IncomeTaxSquare, RegularSquare, etc.
What problem does Protected Variation solve?
Protects system elements from variations or instabilities in other components from causing ripple effects.
What is the solution proposed by the Protected Variation pattern?
Identify variation points and create stable interfaces around them, often using indirection and polymorphism.
What is a contraindication of using Protected Variation?
Excessive speculative future-proofing may add unnecessary complexity and cost.
In the POS example, which interface protects variations in tax calculator adapters?
ITaxCalculatorAdapter defines a stable interface for multiple external tax calculator implementations.
Which design principle is equivalent to Protected Variation?
The Open-Closed Principle (OCP) by Bertrand Meyer, stating modules should be open for extension but closed for modification.
How does Indirection contribute to Protected Variation?
It creates a stable mediator to hide interface variations of external components.
How does Polymorphism contribute to Protected Variation?
It allows multiple implementations behind a common interface to handle behavior variations.
What three fundamental principles are related in the GRASP pattern relationships diagram?
Protected Variation, Low Coupling, and High Cohesion form the core goals, achieved using other patterns.