Software Architecture & Design Patterns Flashcards

(22 cards)

1
Q

Why use design patterns?

A
  • Reusability: Pre-tested solutions
  • Communication: Shared vocabulary
  • Maintainability: Organised code
  • Scalability: Adaptable structure
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does the Singleton pattern work?

A
  1. Private constructor (prevents direct instantiation)
  2. Static instance (ensures single instance)
  3. Public getInstance() method (global access)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Name three creational patterns and their purposes

A
  • Factory: Creates objects without specifying classes
  • Builder: Constructs complex objects step-by-step
  • Singleton: Ensures there’s only one instance in a class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are creational patterns?

A

Patterns focused on object creation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the 3 MVC components?

A
  1. Model: Manages data
  2. View: Displays data
  3. Controller: Handles input and updates Model/View
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the Model do in MVC?

A

Stores data, Enforces business rules, Notifies View of updates

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the View’s role in MVC?

A

Displays data from Model, No business logic, Updates when Model changes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does the Controller handle?

A

Processes user input, Updates Model, Refreshes View

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Describe MVC flow for a bank transfer

A
  1. User (initiateTransfer) -> Controller (validateTransfer)
  2. Controller updates Model (updateBalance)
  3. Controller refreshes View (displayNewBalance)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How does MVC improve maintainability?

A

Changes to one component (e.g View) don’t affect others (Model/Controller)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Name three structural patterns

A
  • Adapter: Allows two incompatible interfaces to collaborate
  • Decorator: Adds behaviours to objects dynamically without altering existing code
  • Composite: Composes objects into tree-like structures
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are structural patterns?

A

Patterns dealing with object composition/relationships

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are behaviour patterns?

A

Patterns managing object communication.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Name three behaviour patterns

A
  • 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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Why is MVC easier to test?

A

Components are isolated

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to make Singleton thread-safe?

A

Use synchronised in getInstance() or static initialisation

17
Q

Name an MVC variant

A

MVVM (Model-View-View-Model) for data-binding (e.g. Angular)

18
Q

MVC key rules

A
  • Model: Only data (no logic)
  • Controller: Orchestrates logic/updates (all communication flows here)
  • View: Passive display
19
Q

When should you use design patterns?

A

When they solve a specific problem - not as a default. Overuse adds complexity

20
Q

What are design patterns?

A

Reusable solutions to common software design problems providing structured approaches to improve code readability and flexibility

21
Q

Advantages of MVC

A
  • Modularity (easy updates)
  • Scalability (add features without disruption)
  • Testability (isolated component testing)
  • Flexibility (multiple UIs for same Model)
22
Q

MVC Flow over Traditional flow

A

Replaces direct interaction with centralised control (Controller), reducing complexity