Software Architecture & Design Patterns Flashcards
(22 cards)
Why use design patterns?
- Reusability: Pre-tested solutions
- Communication: Shared vocabulary
- Maintainability: Organised code
- Scalability: Adaptable structure
How does the Singleton pattern work?
- Private constructor (prevents direct instantiation)
- Static instance (ensures single instance)
- Public getInstance() method (global access)
Name three creational patterns and their purposes
- Factory: Creates objects without specifying classes
- Builder: Constructs complex objects step-by-step
- Singleton: Ensures there’s only one instance in a class
What are creational patterns?
Patterns focused on object creation
What are the 3 MVC components?
- Model: Manages data
- View: Displays data
- Controller: Handles input and updates Model/View
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 (initiateTransfer) -> Controller (validateTransfer)
- Controller updates Model (updateBalance)
- Controller refreshes View (displayNewBalance)
How does MVC improve maintainability?
Changes to one component (e.g View) don’t affect others (Model/Controller)
Name three structural patterns
- Adapter: Allows two incompatible interfaces to collaborate
- Decorator: Adds behaviours to objects dynamically without altering existing code
- Composite: Composes objects into tree-like structures
What are structural patterns?
Patterns dealing with object composition/relationships
What are behaviour patterns?
Patterns managing object communication.
Name three behaviour patterns
- Objects: how a group of objects interact based on state changes
- Strategy: indirectly alters object’s behaviour at runtime
- Command: turns request into a stand-alone object (command)
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)
MVC key rules
- Model: Only data (no logic)
- Controller: Orchestrates logic/updates (all communication flows here)
- View: Passive display
When should you use design patterns?
When they solve a specific problem - not as a default. Overuse adds complexity
What are design patterns?
Reusable solutions to common software design problems providing structured approaches to improve code readability and flexibility
Advantages of MVC
- Modularity (easy updates)
- Scalability (add features without disruption)
- Testability (isolated component testing)
- Flexibility (multiple UIs for same Model)
MVC Flow over Traditional flow
Replaces direct interaction with centralised control (Controller), reducing complexity