Design Pattern in Software Engineering

Design Pattern in Software Engineering

Back in 1994, Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides collectively authored the groundbreaking book “Design Patterns – Elements of Reusable Object-Oriented Software,” marking the inception of the concept of design patterns in software development.

Software design patterns are like blueprints for solving common problems in software development. They provide general reusable solutions to recurring design problems, making your code more flexible, modular, and easier to understand.

Types of Design Patterns

As per the design pattern reference book Design Patterns – Elements of Reusable Object-Oriented Software, there are 23 design patterns which can be classified in three categories: Creational, Structural and Behavioral patterns.

  • Creational Patterns
  • Structural Patterns
  • Behavioural Patterns

Creational Patterns

Creational patterns deal with the process of object creation in a way that is both flexible and efficient. They provide mechanisms to create objects without specifying the exact class of the object that will be created. Examples include the Singleton pattern, Factory Method pattern, and Abstract Factory pattern.

Singleton Pattern ensures a class has only one instance and provides a global point of access to it. For example authentication class.

Factory Method Pattern defines an interface for creating an object but leaves the choice of its type to the subclasses. For example creating a single class shape, which can be then inherited to a circle, triangle etc.

Abstract Factory Pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes. For example, creating a GUI toolkit that supports multiple operating systems.

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

Prototype Pattern creates new objects by copying an existing object, known as the prototype. For example, cloning objects in a graphic design application to create duplicates.

Structural Patterns

Structural patterns focus on organizing different classes and objects to form larger structures. They help in building relationships between objects and ensuring that they work together to achieve a larger goal. Examples include the Adapter pattern, Composite pattern, and Decorator pattern.

Adapter Pattern allows the interface of an existing class to be used as another interface. For example, adapting an old system to a new API or integrating third-party libraries.

Bridge Pattern separates abstraction from implementation so that the two can vary independently. For example, connecting different database interfaces to a data access layer without tying them directly.

Composite Pattern composes objects into tree structures to represent part-whole hierarchies. For example, representing a document structure where both individual elements (characters) and composite elements (paragraphs) are treated uniformly.

Decorator Pattern attaches additional responsibilities to an object dynamically. For example, adding new features or behaviours to a core component without altering its structure.

Facade Pattern provides a simplified interface to a set of interfaces in a subsystem. For example, creating a simplified interface for a complex system to make it easier to use.

Flyweight Pattern minimizes memory usage or computational expenses by sharing as much as possible with related objects. For example, managing a large number of similar objects (e.g., characters in a text editor) efficiently.

Proxy Pattern provides a surrogate or placeholder for another object to control access to it. For example, implementing lazy loading for large objects or controlling access permissions to an object.

Behavioural Pattern

Behavioural patterns are concerned with the interaction and communication between objects. They define the patterns for how objects collaborate and operate together to accomplish tasks. Examples include the Observer pattern, Strategy pattern, and Command pattern.

Chain of Responsibility Pattern passes a request along a chain of handlers. Each handler decides either to process the request or to pass it to the next handler in the chain. For example, handling user input validation in a form where different handlers validate different aspects (e.g., length, format).

Command Pattern encapsulates a request as an object, allowing parameterization of clients with different requests, queuing of requests, and logging of the parameters. For example, implementing a menu system where each menu item is a command that triggers a specific action.

Interpreter Pattern provides a way to evaluate language grammar or expressions. It defines the grammar for the language, as well as an interpreter that interprets the expressions. For example, creating a language interpreter for mathematical expressions.

Iterator Pattern provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation. For example, iterating through elements in a collection without revealing the internal details of the collection.

Mediator Pattern defines an object that centralizes communication between other objects, reducing direct connections between them. For example, implementing a chat application where users communicate through a central chat mediator.

Memento Pattern captures and externalizes an object’s internal state so that the object can be restored to this state later. For example, implementing undo functionality in a text editor or graphic design application.

Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. For example, implementing event handling in a graphical user interface (GUI).

State Pattern allows an object to alter its behavior when its internal state changes. The object will appear to change its class. For example, implementing a vending machine that behaves differently based on its current state (e.g., idle, dispensing, out of stock).

Strategy Pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. For example, implementing various sorting algorithms (bubble sort, quicksort) that can be switched at runtime.

Template Method Pattern defines the skeleton of an algorithm in the superclass but lets subclasses override specific steps. For example, creating a template for a report generation algorithm with specific steps that can be customized by subclasses.

Self Assessment

  • What are the Design Patterns in Software Engineering?
  • In what scenarios would you choose to implement the Singleton pattern, and what benefits does it offer in those situations?
  • How does the Decorator pattern differ from traditional subclassing, and when would you prefer to use it to extend the functionality of a class?

307 thoughts on “Design Pattern in Software Engineering

  1. Hi there! Quick question that’s totally off topic. Do you know how to make your site mobile friendly? My web site looks weird when viewing from my iphone 4. I’m trying to find a theme or plugin that might be able to fix this problem. If you have any suggestions, please share. Cheers!

  2. I was suggested this website by my cousin. I am not sure whether this post is written by him as nobody else know such detailed about my trouble. You’re incredible! Thanks!

  3. certainly like your web site however you need to test the spelling on quite a few of your posts. A number of them are rife with spelling issues and I to find it very bothersome to inform the truth however I抣l certainly come again again.

  4. Someone necessarily help to make critically posts I’d state. That is the very first time I frequented your web page and up to now? I surprised with the analysis you made to make this particular post amazing. Magnificent activity!

  5. I think that a foreclosures can have a important effect on the borrower’s life. House foreclosures can have a Seven to a decade negative relation to a applicant’s credit report. The borrower who has applied for home financing or any kind of loans even, knows that the actual worse credit rating is actually, the more hard it is to obtain a decent loan. In addition, it could possibly affect a borrower’s capability to find a reasonable place to lease or rent, if that gets to be the alternative real estate solution. Interesting blog post.

  6. You can definitely see your skills in the work you write. The world hopes for more passionate writers like you who aren’t afraid to say how they believe. Always go after your heart.

  7. Hmm is anyone else experiencing problems with the pictures on this blog loading? I’m trying to determine if its a problem on my end or if it’s the blog. Any feedback would be greatly appreciated.

  8. Wow that was unusual. I just wrote an very long comment but after I clicked submit my comment didn’t appear. Grrrr… well I’m not writing all that over again. Anyway, just wanted to say excellent blog!

  9. mexican online pharmacies prescription drugs [url=http://mexicandeliverypharma.com/#]best online pharmacies in mexico[/url] mexican rx online

  10. I’m curious if you ever have problems with what people post? Honestly the internet used to be like a different place, except that recently it seems to have become better What are your thoughts? [Reply]

  11. buy cytotec [url=https://cytotec.pro/#]Misoprostol price in pharmacy[/url] cytotec pills buy online

  12. 1хбет зеркало [url=http://1xbet.contact/#]1xbet зеркало рабочее на сегодня[/url] 1xbet официальный сайт

  13. pharmacy program online [url=https://pharmbig24.online/#]japan pharmacy online[/url] mexico online pharmacy

  14. online pharmacy india [url=http://indianpharmacy.company/#]п»їlegitimate online pharmacies india[/url] Online medicine order

  15. Online medicine home delivery [url=https://indianpharmacy.company/#]Online medicine home delivery[/url] online pharmacy india

  16. reputable indian pharmacies [url=https://indianpharmacy.company/#]mail order pharmacy india[/url] indianpharmacy com

  17. cheapest online pharmacy india [url=https://indianpharmacy.company/#]top 10 online pharmacy in india[/url] india pharmacy mail order

  18. indian pharmacies safe [url=http://indianpharmacy.company/#]п»їlegitimate online pharmacies india[/url] buy prescription drugs from india

  19. medicine in mexico pharmacies [url=https://mexicopharmacy.cheap/#]mexican online pharmacies prescription drugs[/url] reputable mexican pharmacies online

  20. viagra online us pharmacy [url=https://pharmbig24.com/#]online pharmacy no prescription lortab[/url] stromectol pharmacy

  21. п»їbest mexican online pharmacies [url=https://mexicopharmacy.cheap/#]mexico drug stores pharmacies[/url] reputable mexican pharmacies online

  22. gates of olympus slot [url=http://gatesofolympusoyna.online/#]gates of olympus giris[/url] gates of olympus oyna

  23. betine promosyon kodu 2024: betine – betine guncel giris
    betine promosyon kodu 2024 [url=http://betine.online/#]betine giris[/url] betine sikayet

  24. starzbet guncel giris: starz bet giris – starzbet guncel giris
    Gates of Olympus [url=http://gatesofolympusoyna.online/#]gates of olympus oyna demo[/url] gates of olympus demo oyna

  25. farmacia gibraltar online viagra [url=http://sildenafilo.men/#]comprar viagra en espana[/url] comprar viagra en espaГ±a envio urgente contrareembolso

  26. sildenafilo 100mg precio farmacia [url=http://sildenafilo.men/#]comprar viagra en espana[/url] comprar viagra online en andorra

  27. Farmacia online miglior prezzo [url=https://tadalafilit.com/#]Cialis generico farmacia[/url] top farmacia online

  28. acquisto farmaci con ricetta [url=https://farmaciait.men/#]Farmacie on line spedizione gratuita[/url] migliori farmacie online 2024

  29. farmaci senza ricetta elenco [url=http://tadalafilit.com/#]Tadalafil generico migliore[/url] top farmacia online

  30. жүрегіңді бер маған емдеп алайын хансамат, жүрегіңді бер маған емдеп алайын
    ремикс скачать азия & бакай тобы
    все песни, азия тобы – ғажайып күй скачать тілім
    менің тірегім презентация,
    тілім менің тірегім сценарий өнертабыс не үшін керек, өнертабыс әлемді
    қалай өзгертеді

  31. Farmacie on line spedizione gratuita [url=http://tadalafilit.com/#]Cialis generico farmacia[/url] comprare farmaci online all’estero

  32. farmacia online senza ricetta [url=https://brufen.pro/#]Brufen 600 senza ricetta[/url] migliori farmacie online 2024

  33. viagra consegna in 24 ore pagamento alla consegna [url=https://sildenafilit.pro/#]viagra[/url] viagra naturale in farmacia senza ricetta

  34. acquistare farmaci senza ricetta [url=https://tadalafilit.com/#]Cialis generico controindicazioni[/url] Farmacie online sicure

  35. viagra generico in farmacia costo [url=http://sildenafilit.pro/#]cialis farmacia senza ricetta[/url] gel per erezione in farmacia

  36. acquisto farmaci con ricetta [url=http://farmaciait.men/#]farmacia online migliore[/url] farmacie online autorizzate elenco

  37. comprare farmaci online con ricetta [url=http://brufen.pro/#]BRUFEN 600 prezzo in farmacia[/url] comprare farmaci online con ricetta

  38. farmacia online [url=http://tadalafilit.com/#]Cialis generico 20 mg 8 compresse prezzo[/url] migliori farmacie online 2024

  39. pharmacie en ligne fiable [url=http://pharmaciepascher.pro/#]Medicaments en ligne livres en 24h[/url] trouver un mГ©dicament en pharmacie

  40. pharmacies en ligne certifiГ©es [url=http://pharmaciepascher.pro/#]Pharmacies en ligne certifiees[/url] trouver un mГ©dicament en pharmacie

  41. киіз үй сүйектері әйтеке бидің өлеңдері, әйтеке бидің шын
    есімін көрсетіңіз антихолинэстеразды заттар,
    холиномиметиктер деген не аниматоры
    в алматы, аниматоры алматы недорого

  42. vente de mГ©dicament en ligne [url=http://clssansordonnance.icu/#]Acheter Cialis[/url] Achat mГ©dicament en ligne fiable

  43. конгресс-холл астана официальный сайт, конгресс-холл астана вместимость
    очки для зрения цены, очки для зрения
    алматы скидки доллар в теңге, курс рубля к тенге снять
    квартиру в талгаре посуточно, маркет аренда квартир в талгаре

  44. нарықтың кемшіліктері, нарықтық
    экономиканың кемшіліктері актау жумыс
    кундик, актау жумыс вахта сор по литературе 3 класс 3 четверть, соч по русской литературе
    за 3 четверть 6 класс жена давлетьярова фото,
    жена армана давлетьярова узбечка

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this:
Verified by MonsterInsights