Design Patterns

Used In

πŸ“š Design Pattern Categories


πŸ“– Definition

Design patterns are descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context. They help create reusable object-oriented software that is flexible, elegant, and maintainable.

"They reuse solutions that have worked for them in the past"

Key Benefits


🎨 Core Principles

State Pattern

Represent states with objects

  • Each possible state of an object is implemented as a separate class or object
  • This allows an object to change its behavior depending on its current state

Decorator Pattern

Model-View Separation

Decoupling views from model β†’ separating the UI (view) from the data and business logic (model)



Guard Clauses Technique

Used to write , Cleaner and more readable code

void someFunction(){
  if (wifi){
    if(login){
      if(admin){
        someFunction();
      } else {
        // Handle non-admin user
        return;
    }
  }else {
    // Handle no login
    return;
    }
  }else {
    // Handle no wifi
    return;
  }
}

This change to

void someFunction(){
  if (!wifi) {
    // Handle no wifi
    return;
  }
  if (!login) {
    // Handle no login
    return;
  }
  if (!admin) {
    // Handle non-admin user
    return;
  }
  someFunction();
}

πŸ“š References