Skip to content

Design Patterns

Master Design Patterns with 51 free flashcards. Study using spaced repetition and focus mode for effective learning in Programming.

🎓 51 cards ⏱️ ~26 min Advanced
Study Full Deck →
Share: 𝕏 Twitter LinkedIn WhatsApp

🎯 What You'll Learn

Preview Questions

12 shown

What are Design Patterns in software engineering?

Show ▼

Design patterns are reusable solutions to commonly occurring problems in software design. They were popularized by the Gang of Four (GoF) in their 1994 book. They are not code, but templates for solving problems that can be adapted to many situations.

Benefits:Provide a shared vocabulary among developersPromote proven, tested solutionsImprove code maintainability and flexibility

What are the three categories of GoF Design Patterns?

Show ▼

The three categories are:

Creational Patterns – Deal with object creation mechanisms (e.g., Singleton, Factory Method, Builder)Structural Patterns – Deal with object composition and relationships (e.g., Adapter, Decorator, Facade)Behavioral Patterns – Deal with communication between objects (e.g., Observer, Strategy, Command)

What is the Singleton pattern?

Show ▼

The Singleton pattern ensures a class has only one instance and provides a global point of access to it.

Key traits:Private constructorStatic method to get the instanceLazy or eager initializationExample: public static Singleton getInstance() { if (instance == null) instance = new Singleton(); return instance; }

What are the drawbacks of the Singleton pattern?

Show ▼

Singleton drawbacks include:Introduces global state, making code harder to testViolates the Single Responsibility Principle (manages its own lifecycle)Thread safety issues if not implemented carefullyTight coupling to the Singleton classOften considered an anti-pattern when overused

What is the Factory Method pattern?

Show ▼

The Factory Method defines an interface for creating objects but lets subclasses decide which class to instantiate.

abstract class Creator {
  abstract Product factoryMethod();
}


Benefits:Follows the Open/Closed PrincipleDecouples client code from concrete classesSubclasses control instantiation

What is the Abstract Factory pattern?

Show ▼

The Abstract Factory provides an interface for creating families of related objects without specifying their concrete classes.

Example: A UI toolkit factory that creates buttons, checkboxes, and menus for different OS platforms.

interface GUIFactory {
  Button createButton();
  Checkbox createCheckbox();
}


Use when the system must be independent of how its products are created.

How does Abstract Factory differ from Factory Method?

Show ▼

Factory Method uses inheritance — a single method in a subclass creates one productAbstract Factory uses composition — a factory object creates a family of related productsFactory Method creates one product; Abstract Factory creates multiple related productsAbstract Factory often uses Factory Methods internally

What is the Builder pattern?

Show ▼

The Builder pattern separates the construction of a complex object from its representation, allowing the same construction process to create different representations.

Pizza pizza = new Pizza.Builder()
  .size("large")
  .cheese(true)
  .pepperoni(true)
  .build();


Use when:An object has many optional parametersConstruction involves multiple steps

What is the Prototype pattern?

Show ▼

The Prototype pattern creates new objects by cloning an existing object (the prototype) rather than using constructors.

Prototype clone = original.clone();

Benefits:Avoids costly creation from scratchHides the complexities of creating new instancesUseful when objects differ only slightlyUses the Cloneable interface in Java or copy constructors in C++.

What is the Adapter pattern?

Show ▼

The Adapter pattern converts the interface of a class into another interface that clients expect. It lets classes work together that couldn't otherwise due to incompatible interfaces.

Analogy: A power plug adapter lets a US plug fit a European socket.

Two forms:Class Adapter – uses multiple inheritanceObject Adapter – uses composition (preferred)

What is the Bridge pattern?

Show ▼

The Bridge pattern decouples an abstraction from its implementation so the two can vary independently.

Example: Shape (abstraction) and Color (implementation) — a RedCircle combines both without creating a class for every combination.

Key benefit: Prevents a cartesian product explosion of subclasses when you have multiple dimensions of variation.

What is the Composite pattern?

Show ▼

The Composite pattern composes objects into tree structures to represent part-whole hierarchies. It lets clients treat individual objects and compositions uniformly.

Example: A file system where both File and Directory implement a common FileSystemComponent interface.

interface Component {
  void operation();
}
class Leaf implements Component {...}
class Composite implements Component {...}

🎓 Start studying Design Patterns

🎮 Study Modes Available

🔄

Flashcards

Flip to reveal

🧠

Focus Mode

Spaced repetition

Multiple Choice

Test your knowledge

⌨️

Type Answer

Active recall

📚

Learn Mode

Multi-round mastery

🎯

Match Game

Memory challenge

Related Topics in Programming

📖 Learning Resources