Software Architecture & Design Patterns Flashcards

(15 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 ensure a single instance?

A
  1. Private constructor
  2. Static instance variable
  3. Public getInstance() method
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Name two creational patterns and their purposes

A
  • Factory: Creates objects without specifying classes
  • Builder: Constructs complex objects step-by-step
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the 3 MVC components?

A
  1. Model: Manages data
  2. View: Displays data
  3. Controller: Handles input
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
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
6
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
7
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
8
Q

Describe MVC flow for a bank transfer

A
  1. User -> Controller (initiateTransfer)
  2. Controller -> Model (validateTransfer, updateBalance)
  3. Controller -> View (displayUpdateBalance)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
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
10
Q

Name two structural patterns

A
  • Adapter: Incompatible interfaces -> compatible
  • Decorator: Adds responsibilities dynamically
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What’s the Observer pattern?

A

Objects (observers) get notified of change

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

How to make Singleton thread-safe?

A

Use synchronised in getInstance() or static initialisation

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

Name an MVC variant

A

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

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

When should you use design patterns?

A

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

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