Design Patterns Review
- 79Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
Who initiated the pattern movement, and in which domain did it begin?
79 questions
- 1
Who initiated the pattern movement, and in which domain did it begin?
Model answer
Christopher Alexander initiated the pattern movement in architecture, particularly through his 1977 book A Pattern Language.
Explanation
The pattern movement began outside software and later influenced software development and software architecture.
- 2
What essential elements did Christopher Alexander identify as necessary parts of a pattern?
Model answer
A pattern needs a context, a problem, the forces that make the problem difficult, a solution, and the consequences of applying that solution.
Explanation
These elements describe when the pattern applies, what it resolves, how it resolves it, and what results from its use.
- 3
Why are the consequences of a design pattern important?
Model answer
Consequences describe the pattern's benefits, drawbacks, and trade-offs, allowing developers to judge whether the resulting design is appropriate.
Explanation
The consequences capture the experience and knowledge gained from applying the pattern.
- 4
How did the pattern movement transfer from architecture to software?
Model answer
The ideas developed in architecture were adopted by software developers and architects, leading to catalogs and books of recurring software solutions.
Explanation
The pattern concept was generalized from architectural problems to software design and architecture.
- 5
What is the significance of the Gang of Four book in software design patterns?
Model answer
The Gang of Four book, Design Patterns: Elements of Reusable Object-Oriented Software, helped establish and popularize design patterns in software development.
Explanation
It collected and summarized patterns from different authors, conferences, and software experiences.
- 6
Who are the four authors known as the Gang of Four?
Model answer
The authors are Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides.
Explanation
Together, these authors produced the most famous foundational catalog of object-oriented software design patterns.
- 7
What role did Douglas Schmidt play in pattern-oriented software architecture?
Model answer
Douglas Schmidt was a major author and collector of patterns in the Pattern-Oriented Software Architecture books; he was not presented as the inventor of all those patterns.
Explanation
His work helped document and communicate patterns through books and educational materials.
- 8
Why are known uses important before a solution is considered a design pattern?
Model answer
Known uses show that the solution has been applied repeatedly in real systems and has proven effective for a recurring problem.
Explanation
Repeated successful application distinguishes a design pattern from an untested idea.
- 9
Define a software design pattern.
Model answer
A software design pattern is a proven, reusable solution idea or template for a recurring design problem.
Explanation
A pattern is not a single concrete implementation; it describes a solution that has worked across multiple projects.
- 10
Why is a design pattern not simply a concrete piece of code?
Model answer
A design pattern provides a general solution idea that can be adapted to different projects and programming languages rather than prescribing one implementation.
Explanation
The pattern captures reusable design knowledge at a level above a particular code listing.
- 11
What information should the context section of a design pattern explain?
Model answer
It should explain the domain and situation in which the pattern applies, such as software development or embedded systems.
Explanation
Patterns are context-dependent and should not be applied outside the type of situation for which they were designed.
- 12
What makes the problem in a design pattern nontrivial?
Model answer
The problem is nontrivial when the appropriate solution is not obvious because competing forces or constraints must be balanced.
Explanation
Examples of forces include limited memory, CPU capacity, or energy in embedded systems.
- 13
What are forces in the context of a design pattern?
Model answer
Forces are competing constraints or pressures that make a design problem difficult and influence which solution is feasible.
Explanation
Forces may pull a design in different directions, such as flexibility versus low resource consumption.
- 14
What should the solution section of a design pattern provide?
Model answer
It should provide a generic description of the participating objects or classes and explain how they collaborate during runtime.
Explanation
The solution includes both the static structure and the dynamic interactions of the design.
- 15
What is the difference between the static and dynamic parts of a pattern solution?
Model answer
The static part describes the participating classes and objects, while the dynamic part describes their runtime interactions, calls, construction, and communication.
Explanation
Both structure and behavior are needed to understand how a pattern works.
- 16
What do the consequences or rationale of a pattern describe?
Model answer
They describe the benefits, liabilities, limitations, and trade-offs that result from applying the pattern.
Explanation
Consequences allow developers to evaluate whether the pattern's effects are acceptable for their requirements.
- 17
Why should a pattern description include limitations?
Model answer
Limitations reveal situations in which the pattern may reduce performance, increase complexity, or become unsuitable.
Explanation
For example, notifying a very large number of observers synchronously can make an application slow.
- 18
What are known users in a pattern description?
Model answer
Known users are real-world examples or implementations showing where the pattern has been applied.
Explanation
They provide evidence that the pattern is practical and repeatedly useful.
- 19
Using the pattern-house metaphor, what does the roof represent?
Model answer
The roof represents the context in which the pattern applies.
Explanation
The context defines the domain and situation that frame the rest of the pattern.
- 20
Using the pattern-house metaphor, what do the interior parts represent?
Model answer
The interior represents the problem, its forces, the solution, and the consequences of applying the solution.
Explanation
These elements are connected because the forces make the problem difficult, the solution addresses the problem, and the consequences result from that solution.
- 21
Using the pattern-house metaphor, what forms the foundation?
Model answer
Known users form the foundation because repeated real-world applications support the pattern's validity.
Explanation
A solution becomes a pattern through repeated, successful use.
- 22
What is the primary purpose of wrapping patterns?
Model answer
Wrapping patterns solve problems by placing another layer of abstraction around an existing component or interface.
Explanation
The Adapter, Proxy, Decorator, and Facade are examples of wrapping patterns.
- 23
Name four wrapping patterns.
Model answer
Four wrapping patterns are Adapter, Proxy, Decorator, and Facade.
Explanation
These patterns place an abstraction around another object or subsystem to alter access, interface, or behavior.
- 24
What is the main purpose of creational patterns?
Model answer
Creational patterns manage or simplify the creation of objects, especially when object construction is complex or variable.
Explanation
They separate object creation concerns from the application code that uses the objects.
- 25
How does the Builder pattern address object creation?
Model answer
Builder constructs an object through multiple defined steps, which is useful when creation is complex.
Explanation
The pattern organizes the construction process instead of requiring one complicated creation operation.
- 26
How does the Prototype pattern support object creation?
Model answer
Prototype uses a template object or class as the basis for creating new objects, potentially at runtime.
Explanation
This approach is useful when new objects should be created by copying or configuring an existing prototype.
- 27
What guarantee does the Singleton pattern provide?
Model answer
Singleton ensures that only one instance of a particular class is created and provides controlled access to that instance.
Explanation
The creation responsibility is taken away from application code and handled by the pattern.
- 28
What is the purpose of behavioral patterns?
Model answer
Behavioral patterns organize or change how objects behave and interact.
Explanation
They focus on algorithms, requests, state changes, communication, and collaboration between objects.
- 29
How does the Strategy pattern represent an algorithm?
Model answer
Strategy encapsulates an algorithm behind an abstract interface so that it can be selected or exchanged without changing the client.
Explanation
It is useful when an algorithm should be chosen dynamically or provided independently of the code that uses it.
- 30
How does the Command pattern encapsulate an operation?
Model answer
Command packages a method, its request, and relevant execution context into an object that can be stored, invoked later, or undone.
Explanation
This separates the request from the object that ultimately performs the operation.
- 31
What problem does the State pattern solve?
Model answer
State changes an object's behavior according to its current state, making it suitable for modeling state machines.
Explanation
The same object can react differently to an action depending on which state it occupies.
- 32
Why is the State pattern especially appropriate for a state machine?
Model answer
A state machine performs different actions and reactions depending on its current state, which is exactly the behavior that State organizes.
Explanation
The pattern separates state-dependent behavior and allows transitions to determine future behavior.
- 33
What are architectural patterns?
Model answer
Architectural patterns influence the structure of an entire software system or application rather than only a small set of components.
Explanation
Layers, Broker, and Model-View-Controller are examples of architectural patterns.
- 34
Name four architectural patterns discussed in the material.
Model answer
Examples include Layers, Broker, Master-Slave, Client-Server, Pipes and Filters, and Model-View-Controller.
Explanation
These patterns organize major system components, responsibilities, communication paths, or data flow.
- 35
What type of problem does the Iterator pattern address?
Model answer
Iterator provides a way to traverse the elements of a collection without exposing the collection's internal representation.
Explanation
Different programming languages implement the iterator concept in different ways.
- 36
What is the main purpose of communication patterns?
Model answer
Communication patterns organize how objects exchange information, often by decoupling senders from receivers or encapsulating information in messages.
Explanation
Messages may be sent between objects locally or across a network.
- 37
What design concern does Model-View-Controller address?
Model answer
Model-View-Controller separates responsibilities among the model, view, and controller and defines how information and control flow between them.
Explanation
Although it can involve communication, its primary concern is structuring responsibilities within an application.
- 38
What concerns do concurrency patterns address?
Model answer
Concurrency patterns address coordination, synchronization, locking, and asynchronous or parallel execution among concurrent activities.
Explanation
Examples include locks, Monitor Object, Active Object, Future, Scoped Locking, and asynchronous operations.
- 39
What is the purpose of a monitor pattern?
Model answer
A monitor coordinates concurrent access to shared data or operations by combining synchronization with the protected object or component.
Explanation
It is one of the concurrency patterns used to control interactions between concurrent activities.
- 40
What is the purpose of an Active Object pattern?
Model answer
Active Object separates method invocation from method execution so that requests can be processed asynchronously by an independent activity.
Explanation
It is a versatile concurrency pattern for decoupling callers from the execution of operations.
- 41
What do Future and asynchronous programming patterns provide?
Model answer
They allow work to proceed asynchronously while providing a way to obtain or coordinate the result later.
Explanation
The material associates Future with asynchronous operations such as
asyncandawait. - 42
What problem do resource-management patterns address?
Model answer
They organize when resources are acquired and released so that programs do not forget to release them.
Explanation
Garbage collection, leasing, and scoped resources are examples of resource-management approaches.
- 43
How does scoped resource management help prevent resource leaks?
Model answer
It associates a resource's lifetime with a defined scope so that the resource is released when execution leaves that scope.
Explanation
The approach reduces the need for programmers to remember every manual release operation.
- 44
How does reference counting manage object lifetime?
Model answer
Reference counting retains an object while references to it exist and deletes the object when no references remain.
Explanation
The technique removes some of the burden of manually determining when an object can be released.
- 45
What is the purpose of the Memento pattern?
Model answer
Memento preserves an object's state so that the state can be saved and restored without exposing the object's internal implementation.
Explanation
It belongs to the group of patterns discussed alongside reference-counting and other general design techniques.
- 46
What does the Chain of Responsibility pattern organize?
Model answer
Chain of Responsibility passes a request through a sequence of potential handlers until an appropriate handler processes it.
Explanation
The pattern avoids requiring the sender to know the specific receiver responsible for handling a request.
- 47
What is the relationship between the Interpreter pattern and an abstract syntax tree?
Model answer
Interpreter commonly represents and evaluates expressions through a structure such as an abstract syntax tree.
Explanation
The pattern and abstract syntax trees are closely related because both support interpreting structured expressions.
- 48
What is reflection in software design?
Model answer
Reflection allows a program to discover information about an object or class at runtime, such as its methods and attributes.
Explanation
The material identifies runtime inspection of available methods and attributes as the core idea of reflection.
- 49
Distinguish an architectural pattern, a classical design pattern, and an idiom.
Model answer
An architectural pattern shapes an entire application, a classical design pattern influences several components, and an idiom solves a small language-specific problem.
Explanation
The distinction is based mainly on scope and dependence on a particular programming language.
- 50
Give one example of an idiom and explain why it is an idiom.
Model answer
Python's
if __name__ == "__main__"construct is an idiom because it is a small, language-specific programming solution.Explanation
Idioms address narrow implementation issues rather than broad, language-independent design problems.
- 51
What does the Single Responsibility Principle require?
Model answer
A class should have one responsibility and therefore only one reason to change.
Explanation
Separating unrelated responsibilities reduces the effects of changes and improves maintainability.
- 52
What does the Open-Closed Principle require?
Model answer
Software entities should be open for extension but closed for modification: their behavior should be extendable without changing their existing source code.
Explanation
Strategy and State can support this principle by allowing behavior to vary through configuration or replacement implementations.
- 53
How can Strategy or State support the Open-Closed Principle?
Model answer
They allow behavior to be changed or extended by supplying different strategies or states without modifying the original controlling class.
Explanation
The original state machine or algorithm structure can remain unchanged while its behavior is varied externally.
- 54
What does the Liskov Substitution Principle require?
Model answer
Objects of derived classes should be usable wherever objects of their base class are expected without breaking the program's correctness.
Explanation
The principle concerns substitutability between a base abstraction and its derived implementations.
- 55
What does the Interface Segregation Principle require?
Model answer
Clients should depend on fine-grained interfaces that contain only the operations they need rather than on one large interface.
Explanation
Restricting an interface to relevant capabilities makes it easier to use correctly.
- 56
What does the Dependency Inversion Principle require?
Model answer
Code should depend on abstractions, such as interfaces or abstract classes, rather than on concrete implementations.
Explanation
Depending on abstractions allows other developers or components to provide different implementations.
- 57
How does dependency inversion improve extensibility?
Model answer
Programming against abstractions allows concrete implementations to be replaced, derived, or supplied independently of the code that uses them.
Explanation
This reduces coupling between high-level logic and particular implementation classes.
- 58
What is decomposition as a programming principle?
Model answer
Decomposition breaks a large, difficult problem into smaller problems or tasks that can be solved step by step.
Explanation
For example, a large thesis can be divided into chapters and individual tasks.
- 59
What is abstraction as a programming principle?
Model answer
Abstraction hides unnecessary implementation details behind a simpler interface or layer.
Explanation
An application developer can send a network message without knowing the details of the underlying frame or protocol headers.
- 60
How do Adapter and Proxy illustrate abstraction?
Model answer
They place a simpler or more suitable interface around a complicated component, hiding details from the client.
Explanation
Wrapping a component can make its functionality easier to access without requiring clients to understand its internals.
- 61
What is decoupling?
Model answer
Decoupling reduces direct dependencies between components so that they can change or communicate without requiring extensive changes elsewhere.
Explanation
Interfaces, abstractions, and delayed binding can help components avoid depending directly on specific partners.
- 62
How can delayed decision-making support decoupling?
Model answer
A decision such as the communication partner or concrete implementation can be selected later, often at runtime, rather than being fixed in the original source code.
Explanation
Late binding reduces the need to recompile or modify unrelated components when a design choice changes.
- 63
What does the principle of usability and simplicity recommend?
Model answer
Interfaces should be intuitive, easy to use correctly, and difficult to use incorrectly.
Explanation
Good interfaces follow user expectations and expose only the complexity needed by their clients.
- 64
Why should developers avoid premature optimization?
Model answer
They should implement what is currently needed and avoid optimizing or designing for distant possibilities that may never occur.
Explanation
Premature optimization can produce unnecessary complexity and over-engineering.
- 65
Why should developers follow the conventions of the programming language and development context?
Model answer
Following established coding styles, tools, and conventions makes code more readable, predictable, and understandable to other developers.
Explanation
Applying an unrelated personal style or unfamiliar tool can make collaboration and maintenance more difficult.
- 66
Why should a design pattern not be used for every programming problem?
Model answer
Patterns can add unnecessary complexity, so they should be used when they address a genuine recurring problem rather than in trivial scripts or simple applications.
Explanation
Using patterns without need is over-engineering and may make a design harder to understand.
- 67
When can design patterns be especially valuable in a larger software project?
Model answer
They are valuable when a project has recurring design problems, needs flexibility, or would otherwise require developers to repeatedly reinvent solutions.
Explanation
Patterns provide established approaches and can help avoid common architectural and implementation problems.
- 68
Why is it useful for developers to know the names and basic ideas of design patterns?
Model answer
Shared pattern names provide concise vocabulary for discussing possible solutions with other developers and students.
Explanation
A name such as Monitor or Command communicates a design idea more efficiently than a long description.
- 69
Why should a design pattern be independent of a specific programming language?
Model answer
A language-independent pattern expresses a general software design solution that can be adapted across different programming languages.
Explanation
Language-specific small-scale solutions are called idioms rather than general design patterns.
- 70
What should a developer evaluate before choosing between two design patterns?
Model answer
The developer should compare their structures, consequences, trade-offs, and fit with the specific requirements and problem.
Explanation
For example, Mediator and Observer may both organize communication but may be appropriate in different situations.
- 71
Why might the Broker pattern be inappropriate for some applications?
Model answer
Broker can introduce communication overhead, registration requirements, and additional processes or machines, so it should be used only when its benefits justify those costs.
Explanation
A versatile pattern is not automatically suitable for every system.
- 72
Why can synchronous use of the Observer pattern harm performance?
Model answer
If millions of observers must be notified synchronously after one data change, the application may spend excessive time informing them and become very slow.
Explanation
The number of observers and the notification strategy are important consequences to evaluate.
- 73
How should design decisions balance forces and consequences?
Model answer
Developers should select the solution whose consequences best satisfy the relevant requirements and constraints, accepting trade-offs where necessary.
Explanation
For example, a lightweight design may use fewer resources but provide less flexibility.
- 74
Why might a lightweight implementation be selected for an embedded system?
Model answer
An embedded system may have limited memory, CPU capacity, or energy, making a resource-efficient solution more feasible than a highly flexible one.
Explanation
Resource constraints are forces that strongly influence architectural and pattern choices.
- 75
What does it mean to make knowledge explicit, findable, understandable, and applicable?
Model answer
Knowledge should be written down, published so others can locate it, structured so they can understand it, and connected to real problems so they can apply it.
Explanation
Application is essential because learning involves using knowledge in real contexts rather than merely memorizing it.
- 76
Why is applying a pattern more important than merely memorizing its definition?
Model answer
Application demonstrates that a learner can recognize an appropriate problem, evaluate consequences, and use the pattern effectively in a real context.
Explanation
The practical value of pattern knowledge lies in making sound design decisions.
- 77
How can experimenting with patterns in one's own projects improve learning?
Model answer
Using patterns in personal problems and project contexts helps learners connect abstract design knowledge to practical decisions and consequences.
Explanation
Independent experimentation supports deeper understanding than following a prescribed solution mechanically.
- 78
What are the main learning outcomes of studying design patterns?
Model answer
Learners should understand pattern theory, recognize common patterns, apply them across languages, evaluate their consequences, avoid misuse, and make balanced design decisions.
Explanation
Pattern expertise combines conceptual knowledge with practical judgment about when and how to apply patterns.
- 79
What is the difference between learning a pattern and learning when to use it?
Model answer
Learning a pattern means knowing its problem, structure, and solution, while learning when to use it requires judging whether its consequences fit a particular context and set of requirements.
Explanation
Appropriate use depends on context, forces, trade-offs, and possible alternatives.

Ask anything
We've read this whole study set, so questions about it get the best answers.