Design Pattern

Amit Dhiman
3 min readJul 5, 2023

Most commonly used design pattern

What is Design Pattern and Why to use them

A design pattern in programming is a reusable solution to a common problem that occurs during software design and development. It provides a structured approach to solving specific design or implementation issues, allowing developers to create more maintainable, flexible, and scalable code.

Design patterns capture best practices and proven solutions that have been refined over time by experienced developers. They provide a common language and set of concepts for discussing and communicating design decisions and patterns of interaction between classes or objects.

Design patterns can be categorized into three main types:

1. Creational Patterns: These patterns focus on object creation mechanisms, providing ways to create objects in a manner that is flexible, decoupled from their concrete implementations, and suited to the specific requirements of the application. Examples include the Singleton pattern, Factory pattern, and Builder pattern.

2. Structural Patterns: These patterns deal with the composition of classes and objects to form larger structures while keeping them flexible and efficient. They help ensure that classes and objects can work together effectively to achieve a common goal. Examples include the Adapter pattern, Decorator pattern, and Composite pattern.

3. Behavioral Patterns: These patterns focus on the interactions and communication between objects and classes. They provide solutions for effectively managing the flow of control, responsibilities, and behavior between objects. Examples include the Observer pattern, Strategy pattern, and Command pattern.

By applying design patterns, developers can improve code reusability, maintainability, and scalability, as well as enhance the overall design and architecture of software systems. However, it’s important to choose and implement design patterns judiciously, based on the specific requirements and constraints of the project, to avoid over-engineering or unnecessary complexity.

Common Design Patterns

Singleton Pattern:

  • Ensures that only one instance of a class is created and provides a global point of access to it.
  • Useful when you want to have a single, shared instance of a class throughout the application.

https://medium.com/@androidtechsolution/singleton-design-pattern-42b97c9b6483

Builder Pattern:

  • Provides a way to construct complex objects step by step.
  • Allows you to create different representations of an object using the same construction process.

https://medium.com/@androidtechsolution/builder-design-pattern-a9ef850a7230

Factory Pattern:

  • Provides an interface for creating objects, but allows subclasses to decide which class to instantiate.
  • Useful when you want to abstract the object creation process and create objects without specifying the exact class.

https://medium.com/@androidtechsolution/factory-design-pattern-aff38fdc56a1

Adapter Pattern:

  • Allows incompatible interfaces of different classes to work together by wrapping one class with another.
  • It acts as a bridge between two interfaces, converting the interface of one class into another interface that clients expect.

https://medium.com/@androidtechsolution/adapter-design-pattern-4a22052bf093

Decorator Pattern:

  • Allows adding new behaviors or functionalities to an object dynamically by wrapping it with one or more decorator objects.
  • Provides an alternative to subclassing for extending the functionality of an object at runtime.

https://medium.com/@androidtechsolution/decorator-design-pattern-cafdf7c3f0b2

Observer Pattern:

  • Defines a one-to-many relationship between objects, so that when one object changes its state, all its dependents are notified and updated automatically.
  • Commonly used in event handling systems, UI updates, and decoupling components.

https://medium.com/@androidtechsolution/observer-design-pattern-40b65b93f09c

Strategy Pattern:

  • Defines a family of interchangeable algorithms and encapsulates each one into separate classes.
  • Allows the algorithm to be selected at runtime based on specific conditions or requirements.

https://medium.com/@androidtechsolution/strategy-design-pattern-12bc747fc009

Facade Pattern:

  • Provides a unified interface to a set of interfaces in a subsystem.
  • Simplifies the usage of complex systems by providing a higher-level interface that hides the underlying complexity.

https://medium.com/@androidtechsolution/facade-design-pattern-9581d1edd243

MVC (Model-View-Controller) Pattern:

  • Separates the application logic into three interconnected components: the model (data and business logic), the view (user interface), and the controller (handles user input and updates the model and view).
  • Promotes separation of concerns and facilitates modular development.

MVVM (Model-View-ViewModel) Pattern:

  • A variation of the MVC pattern that separates the user interface (view) from the business logic and data (model) by introducing a view model.
  • The view model acts as an intermediary between the view and the model, exposing data and operations to the view and facilitating data binding.

--

--

Amit Dhiman

Sr. Software Developer, Frontend developer with 9+ years of experience. Specializing in Kotlin, Java, Angular, Javascript, Typescript, Html and CSS.