codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🎭

Design Patterns

4 / 100 topics
1Introduction to Design Patterns2History of Design Patterns3Benefits of Using Design Patterns4Types of Design Patterns
Tutorials/Design Patterns/Types of Design Patterns
🎭Design Patterns

Types of Design Patterns

Updated 2026-05-15
10 min read

Types of Design Patterns

Introduction

Design patterns are reusable solutions to common problems in software design. They provide a standardized approach to solving issues that arise during the development process, helping developers create more efficient and maintainable code. Design patterns can be categorized into three main types: creational, structural, and behavioral. Each category addresses different aspects of object creation, class and object relationships, and interactions between objects.

Concept

Creational Patterns

Creational design patterns focus on the process of object creation. They provide mechanisms to create objects in a way that is independent of the classes that instantiate them. This allows for more flexible and scalable code, as new types of objects can be introduced with minimal changes to existing code.

Common Creational Patterns:

  • Singleton: Ensures that a class has only one instance and provides a global point of access to it.
  • Factory Method: Defines an interface for creating an object, but lets subclasses decide which class to instantiate.
  • Abstract Factory: Provides an interface for creating families of related or dependent objects without specifying their concrete classes.

Structural Patterns

Structural design patterns are concerned with how classes and objects can be composed to form larger structures. These patterns help in organizing complex systems by defining the relationships between different components.

Common Structural Patterns:

  • Adapter: Converts the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.
  • Decorator: Allows behavior to be added to an individual object, either statically or dynamically, without affecting the behavior of other objects from the same class.
  • Facade: Provides a simplified interface to a complex subsystem.

Behavioral Patterns

Behavioral design patterns are focused on improving communication between objects. They help in defining how objects interact and communicate with each other, making the system more flexible and easier to manage.

Common Behavioral Patterns:

  • Observer: Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
  • Strategy: Enables selecting an algorithm at runtime. It defines a family of algorithms, encapsulates each one, and makes them interchangeable.
  • Command: Encapsulates a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.

Examples

Creational Pattern Example: Singleton

The Singleton pattern ensures that a class has only one instance and provides a global point of access to it. This is useful when exactly one object is needed to coordinate actions across the system.

JavaScript
1class Singleton {
2static instance = null;
3
4constructor() {
5 if (Singleton.instance) {
6 return Singleton.instance;
7 }
8 this.data = 'Singleton Data';
9 Singleton.instance = this;
10}
11
12getData() {
13 return this.data;
14}
15}
16
17const singleton1 = new Singleton();
18const singleton2 = new Singleton();
19
20console.log(singleton1 === singleton2); // true
21console.log(singleton1.getData()); // "Singleton Data"

Structural Pattern Example: Adapter

The Adapter pattern allows incompatible interfaces to work together. For instance, if you have a legacy system that uses an old interface and you want to integrate it with a new system using a different interface.

JavaScript
1class OldSystem {
2request() {
3 return 'Old System Request';
4}
5}
6
7class NewSystem {
8specificRequest() {
9 return 'New System Specific Request';
10}
11}
12
13class Adapter extends OldSystem {
14constructor(newSystem) {
15 super();
16 this.newSystem = newSystem;
17}
18
19request() {
20 return `${this.newSystem.specificRequest()} (adapted from old system)`;
21}
22}
23
24const oldSystem = new OldSystem();
25const newSystem = new NewSystem();
26const adapter = new Adapter(newSystem);
27
28console.log(oldSystem.request()); // "Old System Request"
29console.log(adapter.request()); // "New System Specific Request (adapted from old system)"

Behavioral Pattern Example: Observer

The Observer pattern is used when an object, called the subject, needs to maintain a list of its dependents, called observers, and notify them automatically of any state changes.

JavaScript
1class Subject {
2constructor() {
3 this.observers = [];
4}
5
6subscribe(observer) {
7 this.observers.push(observer);
8}
9
10unsubscribe(observer) {
11 this.observers = this.observers.filter(obs => obs !== observer);
12}
13
14notify(data) {
15 this.observers.forEach(observer => observer.update(data));
16}
17}
18
19class Observer {
20update(data) {
21 console.log(`Observer received data: ${data}`);
22}
23}
24
25const subject = new Subject();
26const observer1 = new Observer();
27const observer2 = new Observer();
28
29subject.subscribe(observer1);
30subject.subscribe(observer2);
31
32subject.notify('Hello Observers!'); // Output: Observer received data: Hello Observers!
33 // Observer received data: Hello Observers!
34
35subject.unsubscribe(observer1);
36
37subject.notify('Observer 2 only!'); // Output: Observer received data: Observer 2 only!

What's Next?

After understanding the basics of design patterns and their types, the next step is to dive deeper into creational patterns. This will provide a solid foundation for creating objects in a flexible and scalable manner.

Stay tuned for more detailed tutorials on each type of design pattern!

Info

Understanding and applying design patterns can significantly improve your software development skills by promoting cleaner, more maintainable code.


PreviousBenefits of Using Design PatternsNext Introduction to Creational Patterns

Recommended Gear

Benefits of Using Design PatternsIntroduction to Creational Patterns