Software Architecture & Design Patterns Flashcards
(15 cards)
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?
- Private constructor
- Static instance variable
- 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
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
Describe MVC flow for a bank transfer
- User -> Controller (initiateTransfer)
- Controller -> Model (validateTransfer, updateBalance)
- Controller -> View (displayUpdateBalance)
How does MVC improve maintainability?
Changes to one component (e.g View) don’t affect others (Model/Controller)
Name two structural patterns
- Adapter: Incompatible interfaces -> compatible
- Decorator: Adds responsibilities dynamically
What’s the 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