Skip to main content

Design Pattern

 Design pattern is time tested solution for reoccurring software design problems. It is reusable solution to common problem in software design. 

It helps in Organizing code, improve scalability and enhance maintainability.

Three major category -

1. Creational (object creation)

  • Factory - eg( Notification (Email/PushNotification/SMS)
  • Abstract Factory

2. Structural

  • Singleton
  • Prototype
  • Adaptor - Non compatible Interface/system , made to communicate
  • Proxy
        eg. (ecommerce platform, use IPaymentProcessor interface implemented for payment, while one of old payment gateway OldPaymentSystem, which is not compatible with IPaymentProcessor, 

3. Behavioral

  • Iterator: 
                Provides a way to access the elements of a collection without exposing its underlying                             representation. 
  • Strategy: (eCommerce application, payment option - credit/Debit card, Paypal/Amex, wallet...)
                Defines a family of algorithms, encapsulates each one, and makes them interchangeable. 
  • Template Method:
                Defines the skeleton of an algorithm in an operation, deferring some steps to subclasses. 


Non Gang Of Four (GOF) pattern:
  • CQRS
  • Repository -(Abstraction over data access layer(DAL)...makes Unit testing easy...)


Adapter with example

Adapting an Old Payment System

Scenario: Developing a modern e-commerce platform that interacts with various payment gateways. However, one of the payment gateways uses an outdated interface that is incompatible with your platform’s current payment interface. Instead of rewriting the legacy code, we can use the Adapter Pattern to integrate it seamlessly.



Comments

Popular posts from this blog

API Basics

 

Algorithm solving Common Patterns & Techniques

  These are targeted data manipulation strategies used to handle arrays, strings, and linked lists efficiently. Two Pointers : Uses two reference pointers to iterate through a data structure simultaneously, typically from opposite ends or at different speeds (Fast & Slow pointers). Sliding Window : Maintains a subset of data (a "window") over a sequential structure to track running statistics without recalculating the whole set. Prefix Sum : Pre-computes and stores cumulative sums of an array to allow for \(O(1)\) constant-time range sum queries. Dynamic Programming (DP ): Dynamic programming is an optimization technique used to solve problems by breaking them down into simpler subproblems and storing the results of these subproblems to avoid redundant computations. It is particularly effective for problems exhibiting overlapping subproblems and optimal substructure. Greedy Algorithm Breadth-First Search (BFS) / Depth-First Search (DFS) : Systematic graph and tree travers...