Design Patterns

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/46

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

47 Terms

1
New cards

Design Pattern

A proven advice for solving a recurring class of problems by providing a template-like solution rather than a finished design.

2
New cards

Purpose of Design Patterns

Increase reusability, maintainability, clarity, and communication among developers.

3
New cards

Notes about Design Patterns

They are language-independent and serve as conceptual templates, not finished code.

4
New cards

Architectural Design Pattern

A high-level solution that defines the structure of a system, dividing it into components/layers and specifying their communication rules.

5
New cards

Scope of Architectural Patterns

Consider the whole application, providing the first level of abstraction.

6
New cards

Common Architectural Patterns

Multi-Layer, MVC

7
New cards

Multi-Layer Pattern

Divides an application into independent layers that provide services to their neighboring layers.

8
New cards

3-Layer Architecture

Presentation layer, Business Rules layer, Data Management layer.

9
New cards

Presentation Layer

Handles UI/UX and interacts with the user.

10
New cards

Business Rules Processing Layer

Handles computations, logic, and application flow.

11
New cards

Data Management Layer

Handles storage, retrieval, and database/file operations.

12
New cards

Layer Awareness

Each layer knows only its neighbors, reducing tight coupling.

13
New cards

Example of Multi-Layer Pattern

Operating systems with GUI → services → kernel layering.

14
New cards

Benefits of Multi-Layer Pattern

Separation of concerns, fewer dependencies, readability, reusability, testability, maintainability.

15
New cards

MVC Pattern

Divides an application into Model, View, and Controller to separate logic from UI.

16
New cards

Model (MVC)

Manages data, business rules, and state changes

17
New cards

View (MVC)

Displays information to the user and receives no direct data-manipulation ability.

18
New cards

Controller (MVC)

Handles user input, interprets View events, updates the Model.

19
New cards

MVC Interaction Flow

User → View → Controller → Model → View updates.

20
New cards

Benefits of MVC

Structural clarity, maintainability, reusable UI components, prevents direct user manipulation of data.

21
New cards

Multiple Views in MVC

One model can update many views simultaneously.

22
New cards

Class Design Pattern

Lower-level design solutions that focus on interactions among a few classes.

23
New cards

Three Types of Class Design Patterns

Creational, Structural, Behavioral.

24
New cards

Singleton Pattern

Ensures exactly one instance of a class exists at runtime and provides global access to it.

25
New cards

Singleton Use Case: Database Connection

Expensive connections are created only once and shared.

26
New cards

How Singleton Works

Private constructor, static instance variable, and a public static getter method.

27
New cards

Why Constructor Is Private

Prevents creation of multiple instances.

28
New cards

Singleton Instance Lifetime

Instantiated once, usually when the class loads.

29
New cards

Composite Pattern

Treats individual objects and composite groups uniformly by having both implement the same interface/abstraction.

30
New cards

Composite Situation Example

Products and bundles both behave as “products,” allowing unified handling.

31
New cards

Why Composite Helps

Simplifies code, supports extension, and unifies behavior of single items and groups.

32
New cards

Composite Structure

Component interface + leaf classes + composite classes containing children.

33
New cards

Façade Pattern

Provides a simplified interface to a complex subsystem, exposing only necessary operations.

34
New cards

Façade Problem Scenario

A client depends on many classes and sees methods it shouldn’t or doesn’t need.

35
New cards

Façade Solution

A wrapper class delegates tasks to subsystem classes but exposes a clean interface.

36
New cards

Façade Benefit

Reduces coupling, hides complexity, and improves client-side code clarity.

37
New cards

Strategy Pattern

Allows selecting an algorithm’s behavior at runtime by encapsulating each variant in its own class.

38
New cards

Strategy Example: Payment Methods

Credit card, PayPal, crypto — each is a strategy implementing PaymentStrategy.

39
New cards

Strategy Example: Sorting Algorithms

Algorithms like merge sort and bubble sort can be swapped.

40
New cards

Strategy Example: AI Solvers

Puzzle-solving algorithms chosen based on context or difficulty.

41
New cards

Context Class (Strategy)

Uses a Strategy interface reference and executes whichever strategy is assigned.

42
New cards

Runtime Behavior Change

Client can switch strategies at any time to alter behavior.

43
New cards

Strategy and Polymorphism

Leverages interface-based polymorphism to abstract algorithm families.

44
New cards

Template Method Pattern

Defines the skeleton of an algorithm in a superclass method, leaving certain steps abstract for subclasses to implement.

45
New cards

Template Method Role

A concrete method calls one or more abstract methods to complete its algorithm.

46
New cards

Subclass Responsibility (Template)

Provide their own implementations for the abstract steps.

47
New cards

Purpose of Template Method

Allows algorithm structure to remain fixed while subclasses customize steps.