CS2002 - Week 8 - Software Architecture & Design Patterns Flashcards

(17 cards)

1
Q

Benefits of 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

Using a private constructor, static instance variable, and 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

MVC flow for a bank transfer.

A

User -> Controller (initiateTransfer)
Controller -> Model (validateTransfer, updateBalance)
Controller -> View (displayUpdateBalance)

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

MVC 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
7
Q

Adapter pattern

A

Incompatible interfaces -> compatible

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

Decorator pattern

A

Adds responsibilities dynamically

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

Observer pattern

A

Objects (observers) get notified of change

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

When should you use design patterns?

A

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

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

What is the View’s role in MVC?

A

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

17
Q

What does the Controller handle?

A

Processes user input, Updates Model, Refreshes View