1/16
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Why use design patterns?
Reusability: Pre-tested solutions
Communication: Shared vocabulary
Maintainability: Organised code
Scalability: Adaptable structure
How does the Singleton pattern ensure a single instance?
Using a private constructor, static instance variable, and public getInstance() method
Name two creational patterns and their purposes
Factory: Creates objects without specifying classes
Builder: Constructs complex objects step-by-step
What are the 3 MVC components?
Model: Manages data
View: Displays data
Controller: Handles input
MVC flow for a bank transfer
User -> Controller (initiateTransfer)
Controller -> Model (validateTransfer, updateBalance)
Controller -> View (displayUpdateBalance)
MVC maintainability
Changes to one component (e.g View) don't affect others (Model/Controller)
Adapter pattern
Incompatible interfaces -> compatible
Decorator pattern
Adds responsibilities dynamically
Observer pattern
Objects (observers) get notified of change
Why is MVC easier to test?
Components are isolated
How to make Singleton thread-safe?
Use synchronised in getInstance() or static initialisation
Name an MVC variant
MVVM (Model-View-View-Model) for data-binding (e.g. Angular)
When should you use design patterns?
When they solve a specific problem - not as a default. Overuse adds complexity
Name two structural patterns
Adapter: Incompatible interfaces -> compatible
Decorator: Adds responsibilities dynamically
What does the Model do in MVC?
Stores data, Enforces business rules, Notifies View of updates
What is the View’s role in MVC?
Displays data from Model, No business logic, Updates when Model changes
What does the Controller handle?
Processes user input, Updates Model, Refreshes View