Design Patterns Overview
- 45Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is the fundamental definition of a design pattern according to the course?
45 questions
- 1
What is the fundamental definition of a design pattern according to the course?
Model answer
Design patterns are well-tested, reusable, and optimal solutions to common software engineering problems, acting as a solution template.
Explanation
The course defines design patterns as 'well-tested reusable solutions' that are 'flexible and adaptable' and 'optimal solutions' used repeatedly
- 2
List three benefits of using design patterns in software development.
Model answer
They provide well-tested reusable solutions, act as a common vocabulary for developers, and save time by using optimized solutions.
Explanation
The course states: 'they are like a common meta language for developers' and 'they have been optimized' and 'they are flexible and adaptable'
- 3
How do design patterns facilitate communication between developers using different programming languages?
Model answer
Design patterns carry over to different programming languages; understanding a pattern in a general manner means it offers the same reusable solution regardless of language implementation.
Explanation
The instructor explains that if you understand a pattern generally, you know it will work across languages like C++ and Java
- 4
What are the three families of design patterns mentioned in the course, and what does each deal with?
Model answer
Creational patterns manage object creation, structural patterns manage complex object hierarchies, and behavioral patterns improve object communication and messaging.
Explanation
The course divides patterns into creational, structural, and behavioral families with those responsibilities
- 5
List all seven design patterns covered in the course and classify each into its family.
Model answer
Creational: Singleton, Factory Method, Builder. Structural: Adapter. Behavioral: Strategy, Observer, State.
Explanation
The course explicitly lists these seven patterns divided into the three families
- 6
Why is it said that 'design patterns are associated with good, well-organized software design'?
Model answer
Because they encapsulate reusable experience from many generations of coders and help avoid inexperienced decisions, like a bag of reusable experience.
Explanation
The instructor says 'think of design patterns as a bag of reusable experience from many generations of coders'
- 7
What is the main problem with using direct constructors to create objects, as described in the context of the Factory Method pattern?
Model answer
The code becomes unnecessarily aware of the exact class type and thus strongly coupled to it, making it hard to add new types without changing existing code.
Explanation
The course says: 'your code is unnecessarily aware of the type of objects that it creates and thus it is strongly coupled with the type'
- 8
Describe the two main tenets of the Singleton pattern.
Model answer
Ensure a class has only one instance and provide easy global access to that instance.
Explanation
The course defines Singleton as ensuring a single instance and providing global access
- 9
What are common use cases for the Singleton pattern?
Model answer
Loggers, caching, thread pools, database connections, and configuration access.
Explanation
The instructor lists these as examples where a single point of access is needed
- 10
Explain the difference between lazy and eager instantiation in the Singleton pattern.
Model answer
Lazy instantiation creates the instance only when first needed; eager instantiation creates it when the class is loaded, ensuring immediate availability.
Explanation
The course discusses both: lazy construction when not sure if needed, eager loading for frequent fast access
- 11
How is thread safety achieved in a Singleton implementation?
Model answer
By using a lock (e.g., threading.Lock) around the critical section that creates the instance, ensuring only one thread can create it at a time.
Explanation
The course shows a thread-safe Singleton with a lock acquired before instance creation
- 12
What are the two variants of the Factory Method pattern discussed?
Model answer
The classic Gang-of-Four variant (one factory per concrete product) and the simple parameterized variant (one factory with a parameter to choose the product).
Explanation
The course covers both: classic where each product has its own factory, and simple/parameterized where one factory uses a parameter
- 13
Why is the simple (parameterized) Factory Method preferred in most projects?
Model answer
It requires only one factory class and is easier to implement and maintain than the classic variant.
Explanation
The course states: 'we're going to use the simplified variant as it is more useful for the majority of projects'
- 14
What is the core purpose of the Builder pattern?
Model answer
To separate the construction of a complex object from its representation so that the same construction process can create different representations.
Explanation
The course motivates Builder with exactly this separation
- 15
What are the main components in the Builder pattern?
Model answer
Product, Builder (abstract), ConcreteBuilder, and Director. The Director controls the building process using a Builder.
Explanation
The UML diagram shows Product, Builder with build methods, ConcreteBuilder, and Director with construct method
- 16
Describe the role of the Director in the Builder pattern.
Model answer
The Director defines the sequence of building steps and delegates the actual construction to a specific Builder, which can be swapped.
Explanation
The course explains: 'the director then delegates to a specific Builder' and 'calls all the specific methods in a predefined sequence'
- 17
What problem does the Adapter pattern solve?
Model answer
It converts the interface of a class into another interface that a client expects, allowing classes with incompatible interfaces to work together.
Explanation
The course defines Adapter as converting interface, and gives examples of data format and interface incompatibility
- 18
List the steps to design an Adapter as per the course.
Model answer
- Identify the adaptee (service). 2. Declare the client interface. 3. Create adapter class implementing client interface. 4. Add private field for adaptee reference. 5. Implement each method by delegating to adaptee with conversion. 6. Ensure clients use adapter through the interface.
Explanation
The course provides these six design steps for implementing an Adapter
- 19
What is the key idea of the Strategy pattern?
Model answer
Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
Explanation
The course quotes Gang of Four: 'Define a family of algorithms, encapsulate each one, and make them interchangeable'
- 20
How does the Strategy pattern promote the Open/Closed Principle?
Model answer
New strategies can be introduced without changing the context class, as the context only depends on the strategy interface.
Explanation
The course explicitly says Strategy follows OCP: 'You can introduce new strategies into the context without breaking any client code'
- 21
Describe the Observer pattern in terms of publisher and subscriber.
Model answer
The publisher (subject) maintains a list of subscribers (observers) and notifies them automatically when its state changes.
Explanation
The course defines Observer as an event notification mechanism between objects, similar to publisher-subscriber
- 22
How does the Observer pattern relate to the Model-View-Controller (MVC) architecture?
Model answer
The Observer pattern is a key part of MVC, as it allows the model (subject) to notify views (observers) of state changes without tight coupling.
Explanation
The course states: 'The Observer pattern is also a key part in the well-known and utilized Model View Controller MVC architectural pattern'
- 23
What is the main similarity and difference between the Strategy and State patterns?
Model answer
Both use composition to delegate work, but Strategy makes algorithms independent and unaware of each other, while State allows an object to alter its behavior when its internal state changes (states know about transitions).
Explanation
The course compares: 'Strategy makes these objects completely independent and unaware of each other. However, the State pattern allows the objects to alter their behavior when the internal State changes'
- 24
Explain the concept of a finite state machine and how it relates to the State pattern.
Model answer
A finite state machine has a finite number of states with discrete transitions between them; the State pattern models this by having each state as a class that knows how to transition to the next state.
Explanation
The course says: 'State pattern is similar to the concept of finite state machines' and shows a state diagram with states and transitions
- 25
Using the traffic light example, describe how each state class handles the transition.
Model answer
Each state class (Green, Yellow, Red) implements a 'next' method that sets the context's state to the next state: Green->Yellow, Yellow->Red, Red->Green.
Explanation
The code example shows that GreenState sets next state to YellowState, etc.
- 26
What are the three steps of the development cycle mentioned in the context of software architecture?
Model answer
- Gather requirements. 2. Design/architect the system. 3. Implement (code and test).
Explanation
The course describes: 'you start with requirements... then you do a design... finally you implement'
- 27
Why is UML used to document design patterns in the course?
Model answer
UML is a good tool to document well-defined design patterns because it provides a highly visual representation of their structure, specifically using class diagrams and sequence diagrams.
Explanation
The instructor says: 'UML is a good tool to document something as well defined as design patterns... it is a highly visual representation'
- 28
What two types of UML diagrams are used in the course, and what does each convey?
Model answer
Class diagrams show the structure (classes and relationships); sequence diagrams show the interaction/behavior over time (message exchange).
Explanation
The course explicitly states: 'we'll only use two types of diagrams – class diagrams and sequence diagrams'
- 29
What is the difference between a white diamond and a black diamond in a UML class diagram?
Model answer
A black diamond indicates composition (part cannot exist without the whole); a white diamond indicates aggregation (part can exist independently).
Explanation
The course explains with the house example: black diamond for bathroom (destroy house destroys bathroom), white diamond for pool (pool can exist without house)
- 30
Define loose coupling and explain why it is a hallmark of good architecture.
Model answer
Loose coupling means weak knowledge association between components; changes to one component minimally affect others. It leads to easier testing, maintenance, and flexibility.
Explanation
The course states: 'Loose coupling is weak knowledge association between components' and shows tight vs loose coupling diagrams
- 31
What is the Law of Demeter (LoD) or principle of least knowledge?
Model answer
A unit should only talk to its immediate friends; it should not talk to strangers. Each unit should have limited knowledge about other units, only about closely related ones.
Explanation
The course defines LoD as 'each unit should have only limited knowledge about other units' and 'should only talk to its friends'
- 32
List the five SOLID principles of object-oriented programming.
Model answer
Single Responsibility Principle, Open/Closed Principle, Liskov Substitution Principle, Interface Segregation Principle, Dependency Inversion Principle.
Explanation
The course lists all five by name
- 33
What does the Single Responsibility Principle (SRP) state?
Model answer
There should never be more than one reason for a class to change; each class should have only one central responsibility.
Explanation
The course gives exact definition: 'There should never be more than one reason for a class to change'
- 34
Explain the Open/Closed Principle (OCP).
Model answer
Software entities should be open for extension but closed for modification; you should extend a class rather than modify it.
Explanation
The course states: 'Software entities should be open for extension but closed for modification'
- 35
What is the Liskov Substitution Principle (LSP)?
Model answer
Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it; a subtype must be substitutable for its base type.
Explanation
The course gives this definition: 'Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it'
- 36
What does the Interface Segregation Principle (ISP) require?
Model answer
Clients should not be forced to depend upon interfaces they do not use; avoid fat interfaces by splitting them into smaller, specific ones.
Explanation
The course says: 'Clients should not be forced to depend upon interfaces that they do not use'
- 37
What is the Dependency Inversion Principle (DIP)?
Model answer
Depend upon abstractions, not concretions; high-level modules should not depend on low-level modules, both should depend on abstractions.
Explanation
The course states: 'You should depend on abstraction not concretions'
- 38
In Python, what is the difference between
__new__and__init__?Model answer
__new__is a static method that creates and returns a new instance;__init__is an instance method that initializes the object's attributes after creation.__new__runs first.Explanation
The course explains: 'new creates an instance and then init initializes it'
- 39
How are abstract classes distinguished from interfaces in Python?
Model answer
Python does not have a formal interface keyword; interfaces are typically implemented as abstract classes with all abstract methods (no implementation). Abstract classes can have concrete methods and attributes.
Explanation
The course says: 'In Python we do not really have strict interface syntax... we can use an abstract class with no implementation to the methods'
- 40
What is the purpose of the
@abstractmethoddecorator in Python?Model answer
It declares a method as abstract, meaning any concrete subclass must provide an implementation of that method.
Explanation
The course uses
@abstractmethodto define abstract methods that must be overridden - 41
What are the three rules for Conway's Game of Life regarding cell survival and birth?
Model answer
- Any live cell with 2 or 3 live neighbors survives. 2. Any dead cell with exactly 3 live neighbors becomes alive (birth). 3. All other live cells die, and all other dead cells stay dead.
Explanation
The course lists these three exact rules
- 42
How is the Game of Life described as a 'zero-player game'?
Model answer
Its evolution is determined by its initial state, requiring no further input. The user only creates the initial configuration and then observes how it evolves.
Explanation
The course states: 'the game of life is a zero player game its evolution is determined by its initial State requiring no further input'
- 43
What design pattern could be used to handle the timer tick that triggers each generation in the Game of Life?
Model answer
The Observer pattern: the timer (publisher) notifies subscribers (e.g., the grid renderer or game logic) at each tick.
Explanation
The course hints: 'you could then use an observer pattern for what happens when the timer generates a tick'
- 44
Why is the Game of Life a suitable project for applying multiple design patterns?
Model answer
It is complex enough that good architecture makes a difference, yet simple enough to develop in a busy schedule. It utilizes all the design patterns learned in the course.
Explanation
The course says: 'It's going to utilize all the design patterns we have learned in this course' and 'it is complex enough that a good architecture will make a huge difference'
- 45
What is the first recommended step in designing the Game of Life application architecture?
Model answer
Write down the general workflow: create and initialize the grid, set initial organisms, start simulation with a tick interval, compute next generation at each tick, render, and allow stopping.
Explanation
The course provides a high-level workflow: 'create and initialize the simulation grid... start the simulation... compute the new generation... render... stop'

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