1/41
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is a design pattern?
A time-tested, general solution to a recurring design problem, documented as a named problem-solution pair.
Where did the concept of design patterns originate?
From architecture: Christopher Alexander’s "Pattern Language" (1977).
What are the three categories of GoF patterns?
Creational (object creation), Structural (object composition), and Behavioral (object communication).
What is the purpose of the Façade pattern?
Provide a simplified, unified interface to a complex subsystem, reducing coupling.
What problem does the Façade pattern solve?
Direct coupling between clients and many subsystem interfaces makes code fragile and hard to change.
How does the Façade pattern solve this problem?
Introduce a facade object that wraps subsystem components and presents a tailored interface.
Which GoF category does Façade belong to?
Structural pattern.
Give an example of Façade in the POS rules engine context.
POSRuleEngineFacade exposes isInvalid(sli, sale) instead of clients calling each rule implementation directly.
Give an example of Façade in the ATM system context.
BankAccountFacade provides depositCash() and withdrawCash(), hiding account number check, security code, and funds check subsystems.
What is the purpose of the Decorator pattern?
Dynamically add responsibilities to individual objects without altering their interface.
What problem does the Decorator pattern solve?
Inheritance is static and applies to entire classes, not individual instances at runtime.
How does the Decorator pattern work?
Wrap the original object in a decorator object that implements the same interface and adds behavior recursively.
Which GoF category does Decorator belong to?
Structural pattern.
What is recursive composition in the Decorator pattern?
Each decorator holds a reference to a component (base or another decorator), allowing multiple layers of decoration.
Give an example of the Decorator pattern with shapes.
ShapeDecorator wraps a Rectangle, adding behaviors like setRedBorder() and setBlueFill() while preserving draw() interface.
What is the purpose of the Builder pattern?
Separate construction of a complex object from its representation and allow different representations using the same process.
What problem does the Builder pattern solve?
Complex multipart object creation with varying representations can bloat classes and mix construction logic.
How does the Builder pattern work?
Use a Director to control a Builder interface; ConcreteBuilders implement steps to build different products.
Which GoF category does Builder belong to?
Creational pattern.
Name the key roles in the Builder pattern.
Client, Director, Builder (interface), ConcreteBuilder(s), and Product.
Give an example of the Builder pattern for making juice.
JuiceMaker (Director) calls AppleJuiceMaker or OrangeJuiceMaker (ConcreteBuilders) to assemble juice parts in steps.
Give an example of the Builder pattern for creating travel packages.
TravelAgency (Director) uses CruisePackageBuilder or RoadTripBuilder to assemble tickets, hotels, activities, and meals.
What problem does the Adapter pattern solve?
It resolves incompatible interfaces by converting an external component’s interface into one the client expects.
What is the core solution of the Adapter pattern?
Introduce an intermediate adapter object that implements a stable interface and delegates calls to the varying external APIs.
Which category of GoF patterns does Adapter belong to?
Structural pattern.
How does the Adapter pattern relate to GRASP principles?
It is a form of Indirection and Pure Fabrication, uses Polymorphism, achieves Protected Variation, and supports Low Coupling.
In the POS system, what interface do tax adapter classes implement?
ITaxCalculatorAdapter with method getTaxes(Sale): List
How does an Adapter decouple the POS from external services?
By hiding protocol and API differences behind a common interface, so the POS only depends on the adapter interface.
What common interface is defined in the Disney Madness example?
IDisneyAdapter with method move(), representing character movement.
What do TaxMasterAdapter and GoodAsGoldTaxProAdapter do?
They implement ITaxCalculatorAdapter to adapt their vendor-specific tax APIs to the POS’s expected interface.
What problem does the Concrete Factory pattern address?
Separating complex object-creation logic (e.g., adapter instantiation) into a cohesive helper class.
What are the advantages of using a Concrete Factory?
Hides complex creation, supports lazy instantiation, enables caching or recycling, and centralizes creation logic.
How can a factory be implemented in a data-driven way?
By reading adapter class names from a properties file and using reflection to instantiate them.
What issue arises when deciding who creates adapters?
Domain classes like Register shouldn’t create adapters, as adapter creation is not part of business logic.
What pattern solves the issue of adapter creation responsibility?
Use GRASP Pure Fabrication by encapsulating adapter creation in a Concrete Factory.
What problem does the Singleton pattern solve?
Ensures exactly one instance of a class and provides a global point of access to it.
How is the Singleton pattern typically implemented?
With a static synchronized getInstance() method that lazily initializes and returns the sole instance.
How is a Singleton depicted in UML class diagrams?
Static attributes/methods are underlined, and an optional '1' indicates only one instance.
How does the Register class access the singleton ServicesFactory?
By calling ServicesFactory.getInstance().getAccountingAdapter() inside its initialization.
Why aren’t all factory methods static?
Static methods can’t be overridden, hinder RMI support, and reduce flexibility if multiple instances become necessary.
How do Adapter, Factory, and Singleton patterns work together?
Adapter provides stable interfaces, Factory centralizes adapter creation, and Singleton ensures one Factory instance with global access.
Why is using a pattern language valuable in team-based software design?
It provides a shared vocabulary for succinctly explaining design reasoning and solutions among developers.