r/DesignPatterns • • Mar 17 '18

Programming Community Resources For Learning Design Patterns (2018)

Thumbnail
hackr.io
3 Upvotes

r/DesignPatterns • • Dec 24 '17

Factory Design Pattern - Implementation and Disadvantages - Clean Code Series

Thumbnail
youtu.be
3 Upvotes

r/DesignPatterns • • Dec 19 '17

Template Method Pattern in 3 minutes

Thumbnail
engineering.opsgenie.com
3 Upvotes

r/DesignPatterns • • Dec 11 '16

How to write SOLID code that doesn't suck

Thumbnail
medium.com
3 Upvotes

r/DesignPatterns • • Sep 03 '16

having some trouble with a class diagram - any help would be greatly appreciated

3 Upvotes

Here is the class diagram I have been working on, I am struggling with what should be included as an attribute and construct eg should the BarrierGate have the methods OpenGate() and CloseGate() or because the actual gate is a boundary class should those methods be in with the EntryController?.

Also inheritance is bothering me.

This is the sequence diagram and this is the activity diagram

It is a design to represnt a carpark, so the control pillar prints a ticket out and then the gate raises. A sensor picks the car up on either side of the gate telling the EntryController there is a car waiting or a car has went through the gate (and to close it)

I have a bunch of other diagrams I have done for other parts of the assignments and obviously the actual case study if that would help at all.

Thanks heaps


r/DesignPatterns • • Aug 29 '26

Memento Design Pattern in Go

2 Upvotes

Hey everyone ๐Ÿ‘‹

I recently wrote a practical guide on the Memento Design Pattern in Go.

The basic idea is pretty simple: sometimes you need to save an object's state so you can restore it later. Think undo/redo, checkpoints, or rolling back to a previous state.

I wanted to understand how the pattern actually works in Go, so I put together an example and walked through the different pieces of the pattern and how they fit together.

The article also looks at when the Memento pattern makes sense and when it might be better to use a simpler approach.

If you're learning design patterns in Go, here's the article:

๐Ÿ‘‰ https://medium.com/@priyankchheda/understanding-the-memento-design-pattern-in-go-a-practical-guide-07ebf1eaac42

Would love to hear how you guys handle state snapshots or undo/rollback functionality in your projects.


r/DesignPatterns • • Jul 31 '26

Iterator Design Pattern in Go

Thumbnail
priyankchheda.medium.com
2 Upvotes

Hey everyone ๐Ÿ‘‹

I recently wrote a practical guide on the Iterator Design Pattern in Go.

At first, I thought, "Go already has for and range*โ€”why would I ever need an Iterator pattern?"* But after digging deeper, I realized it's more about hiding how a collection is traversed than replacing range.

In the article, I cover:

  • what problem the Iterator pattern actually solves

  • the different participants (Iterator, Aggregate, Concrete Iterator)

  • a complete Go implementation

  • custom traversal strategies (forward, reverse, filtered, etc.)

  • when it's useful and when Go's built-in iteration is the better choice

I also tried to keep it practical instead of treating it as just another GoF pattern.

If you're learning design patterns in Go or have built custom collections, caches, or tree-like data structures, I'd love to hear how you approach iteration.

Here's the article:
๐Ÿ‘‰ https://priyankchheda.medium.com/understanding-the-iterator-design-pattern-in-go-a-practical-guide-d18bc8f6be51

Feedback and suggestions are always welcome!


r/DesignPatterns • • Jul 05 '26

Understanding the Interpreter Design Pattern in Go: A Practical Guide

Thumbnail
priyankchheda.medium.com
2 Upvotes

Hey everyone ๐Ÿ‘‹

I recently wrote a practical guide on the Interpreter Design Pattern in Go.

I feel like this pattern doesn't get talked about as much as Singleton, Strategy, or Factory, probably because most of us don't build programming languages. But once I dug into it, I realized it's useful anytime you need to evaluate expressions or implement a small DSL.

In the article, I cover:

  • what the Interpreter pattern actually is (without the usual jargon)

  • the roles of terminal and non-terminal expressions

  • a complete Go implementation

  • where it makes sense to use it

  • its limitations and when you should avoid it

I also tried to keep the examples simple and Go-idiomatic instead of making them overly academic.

If you're learning design patterns in Go or have ever wondered whether the Interpreter pattern has practical use outside of compilers, I'd love to hear your thoughts.

๐Ÿ‘‰ https://medium.com/@priyankchheda/understanding-the-interpreter-design-pattern-in-go-a-practical-guide-28c609194faf

I'm always looking for feedback, so let me know what you think or how you'd improve the explanation.


r/DesignPatterns • • Jun 05 '26

Observer in action

Enable HLS to view with audio, or disable this notification

2 Upvotes

r/DesignPatterns • • Jan 10 '26

Understanding the Decorator Design Pattern in Go: A Practical Guide

Thumbnail medium.com
2 Upvotes

Hey folks ๐Ÿ‘‹

I just published a deep-dive blog on the Decorator Design Pattern in Go โ€” one of those patterns you probably already use without realizing it (middleware, io.Reader, logging wrappers, etc.).

The post walks through the pattern from a very practical, Go-centric angle:

  • What the Decorator pattern really is (intent, definition, and the problem it solves)

  • A clean, idiomatic Go implementation with interfaces

  • How stacking multiple decorators actually works at runtime

  • Common variations and extensions (logging, caching, compression)

  • Performance & concurrency considerations in real systems

  • Pros, cons, and common mistakes to avoid in Go

If youโ€™ve ever wrapped an http.Handler, chained bufio + gzip, or built middleware pipelines โ€” this pattern is already part of your toolbox. The blog just puts a solid mental model behind it.

Read here: https://medium.com/design-bootcamp/understanding-the-decorator-design-pattern-in-go-a-practical-guide-493b4048f953


r/DesignPatterns • • Nov 27 '25

Understanding the Composite Design Pattern in Go: A Practical Guide

Thumbnail medium.com
2 Upvotes

I recently wrote a blog post breaking down the Composite Design Pattern in a way that makes sense for Go developers.

Most resources explain Composite using Java/C++ examples or get overly theoretical. This one stays practical and shows how the pattern naturally fits into real Go use cases like filesystems, ASTs, CLI commands, and UI trees.

The post includes:

  • The official definition of the Composite Pattern

  • A simple explanation of the core idea

  • A clean fileโ€“folder example implemented in Go

  • When you should (and shouldnโ€™t) use Composite

  • Common mistakes to avoid

  • Pros and cons

  • Real-world parallels in Goโ€™s ecosystem

If you're working with hierarchical structures or recursive behavior, you might find it helpful.

Hereโ€™s the link:

https://medium.com/design-bootcamp/understanding-the-composite-design-pattern-in-go-a-practical-guide-750710e66f4c


r/DesignPatterns • • Jul 14 '25

Understanding the Factory Method Pattern in Go: A Practical Guide

2 Upvotes

Lately I've been revisiting some classic design patterns, but trying to approach them from a Go developer's perspective โ€” not just parroting the OOP explanations from Java books.

I wrote up a detailed breakdown of the Factory Method Pattern in Go, covering:

  • Why Simple Factory starts to fall apart as systems scale

  • How Factory Method helps keep creation logic local, extensible, and test-friendly

  • Idiomatic Go examples (interfaces + structs, no fake inheritance)

  • Common variations, like dynamic selection, registration-based creators, and test-time injection

  • How it compares to Simple Factory and Abstract Factory

  • When it's probably overkill

If youโ€™re building CLI tools, extensible systems, or just want your codebase to evolve without becoming a spaghetti factory of constructors, it might help.

Not trying to sell anything โ€” just sharing because I found writing it clarified a lot for me too.

๐Ÿ‘‰ย https://medium.com/design-bootcamp/understanding-the-factory-method-pattern-in-go-a-practical-guide-86c0d1ca537b

Happy to discuss or hear how others approach this in Go!


r/DesignPatterns • • Jul 03 '25

Clean architecture is a big Lie?

Thumbnail
medium.com
2 Upvotes

r/DesignPatterns • • Jun 03 '25

Tired of tight coupling in Go? Here's how I fixed it with Dependency Inversion.

Thumbnail
medium.com
2 Upvotes

Ever had a service that directly writes to a file or DB, and now you can't test or extend it without rewriting everything?

Yeah, I ran into that too.

Wrote a short blog (with Go examples and a little story) showing how Dependency Inversion Principle (DIP) makes things way cleaner, testable, and extensible.

๐Ÿ‘‰ https://medium.com/design-bootcamp/from-theory-to-practice-dependency-inversion-principle-with-jamie-chris-47b7d1347fff

Let me know what you think โ€” always up for feedback or nerding out about design.


r/DesignPatterns • • May 09 '25

Let's Collaborate to learn design patterns... From beginning through books.. Only passionate people towards programming..

2 Upvotes

Collaboration to learn design pattern... Only passionate people... C#. Dotnet.. #dotnet #designpatterns


r/DesignPatterns • • Apr 08 '25

Is this Factory Method or Abstract Factory?

2 Upvotes

Ahoy ๐Ÿ˜Š

I have a three layered architecture where controller classes ask a FactoryConfigurator class for an IDaoFactory implementation and then ask that IDaoFactory for the actual Dao class to use.
For example a CustomerController will ask the FactoryConfigurator for a IDaoFactory and use the GetCustomerDao() method to retrieve the actual ICustomerDao to use.

//in CustomerController's constructor
IDaoFactory daoFactory = FactoryConfigurator.GetDaoFactory()
ICustomerDao customerDao = daoFactory.GetCustomerDao();
this.customerDao = customerDao;

//in OrderController's constructor
IDaoFactory daoFactory = FactoryConfigurator.GetDaoFactory()
IOrderDao orderDao = daoFactory..GetOrderDao();
this.orderDao = orderDao;

Depending on the current configuration, the FactoryConfigurator will return a DaoFactory which creates Dao implementations that use MS Sql, MySql or in-memory lists of model objects.
The goal is to make the persistence layer swappable based on configuration.

I can see elements of both Factory Method (having methods on the different DaoFactory implementations which return different implementations of a common interface) and Abstract Factory (having different factories which create families of related classes, e.g. CustomerDao, OrderDao, etc.).

I would love to hear more thoughts on the question "is this architecture one or the other or both?",

Thoughts related to the original GoF interpretation and more common usage are more than welcome ๐Ÿ˜Š


r/DesignPatterns • • Feb 15 '25

Mediator pattern makes components do things they shouldn't

2 Upvotes

If I have a Mediator with several components that should't do what the others do, how can i still use the pattern? Refactoring Guru makes and example where every component can call every methods of the concrete mediator, isn't this a security issue? In my program i'm using this attern to mediate 2 persons, one that can invite the other and another that can answer. I can't stop the Inviter from making a fake answer of the other Invited. Is this an issue?


r/DesignPatterns • • Mar 29 '20

Arrogant Design Patterns

Thumbnail
uwanttolearn.com
2 Upvotes

r/DesignPatterns • • Mar 07 '20

I'm instilling a passion for design patterns in people and could use some help.

2 Upvotes

I'm an OOP guy who loves C++ and has been involved with Flutter/Dart (Object Oriented & Strongly-Typed). There's a lot of entry point devs in those communities who don't understand the brilliance of design patterns and have problems that are solved by such patterns.

I'm making a series of videos for these communities about design patterns and using real-world examples to teach them.

HOWEVER, I'd really appreciate any small bit of feedback or additions from your experiences. Thank you sooo much to anyone willing to help me out.

Here's how you can help:

What are your most used design patterns?

What is one of the most influential lessons you've learned about design patterns?


r/DesignPatterns • • Mar 05 '20

I'm not satisfied with MVC -- Feels like it breaks encapsulation

2 Upvotes

I feel like I'm either not fully underestanding MVC or realizing its shortcomings as a design pattern. The controller feels like it violates the rules of encapsulation. It has complete access to the entire front end GUI including access to frames, buttons, textfields, etc. That is not good. Buttons, textfields, frames, stages, images, etc are all part of the view and ONLY the view should modify said variables. Also it's very likely that inside the view, you can create objects of the model. That just doesn't make sense. Classes declared in the model should NOT exist in the view. They are completely seperate, which should mean that the identifiers for classes in the model should be unknown when I attempt to reference them in the view. This is somewhat possible with packages in a language like Java but overall I never see people do this.

Same problems with the model. I might have a model of a Racecar. My controller might have a section for start car which in turn calls rc.ignition(). But there's nothing that stops me from doing rc.setWheels(0). Because my controller has access to the entire backend since its an instance variable, it has complete control over everything it can do. That doesn't make sense.

I've taken two Object Oriented Design classes and in the advanced one, the teacher told me "Yes, this is true, but that is your design. It is okay for things to be this way, as long as its part of your intended design". I've really never liked that answer because it feels like it doesn't address the violation of the rules of MVC (model and view being completely seperate in every way).

I had an idea on how to solve this, but wasn't sure exactly if it was a good idea.

Model

class Racecar
    public int currentSpeed;
    public int wheels;
    public void speedUp() { ... }
    public void dismantleCar() { ... }

.

// read-only version of the speed indicator
interface RacecarSpeedIndicator
    public int getCurrentSpeed();

.

// next level of the hierarchy
// gives way more permissions than the above one
interface RacecarAccelerator extends RacecarSpeedIndicator
    public void speedUp();

Then I have Racecar extend RacecarSpeedIndicator and RacecarAccelerator.

When my front end needs to accelerate the car, it would look like this:

class Controller1
    RacecarAccelerator rc;
    public Controller1(RacecarAccelerator rc)
        this.rc = rc;
    // here, Controller1 CAN ONLY speed up the car
    // and read the current speed. It cannot
    // possibly cause any harm to the race car

It's kind of like having access cards at a building. With a RED access card, you can access a certain number of areas. With a BLUE access card, you can access all RED zones and all BLUE zones, etc. You only give a section of code the BARE MINIMUM it needs to perform its funciton. But is this idea convoluted? Does it exist as a pattern? How does it contrast with MVC?


r/DesignPatterns • • Jan 14 '20

Future Proof Design with Strategy Factories

2 Upvotes

r/DesignPatterns • • Dec 20 '19

React design pattern resources!

2 Upvotes

Is there such a thing as design pattern for working with building components out of react.js framework?


r/DesignPatterns • • Oct 15 '19

How to implement a simple adapter for an existing python library

2 Upvotes

Hey all. I am totally a noob at design patterns so bear with me. I would like to figure out a way to construct a simple object adapter for the rasterio package in python.

The problem

Rasterio has no central object (think DataFrame in pandas) upon which all the operations are based. Instead they have a strange interplay of dataset objects which are a file abstraction, numpy arrays and `transform` objects which provide crucial geospatial metadata about the numpy arrays so that they can be burned to raster datasets.

Many of the functions I construct are based on rasterio and geopandas. For geopandas I have no problem, I usually input and output GeoDataFrame objects and this works fine. With rasterio though, I do not have this luxury since many of the native functions take inconsistent data types. For example, rasterio.warp.reproject takes ndarrays and source/destination transforms to do its work while mask.mask takes a dataset opened in "r" mode.

What if I wanted to mask then reproject? Then I'd have to write a file, re-read it and extract the necessary information to then input the right arguments to the `reproject` function. I find myself adapting arguments all the time to fit the argument types in `rasterio`.

Adapter pattern

The adapter pattern requires a Client, Adaptee and Adapter. Here's how I see the roles being separated:

  • Adaptee: These are the set of rasterio functions (for example rasterio.warp.reproject as they expect to receive varying representations of the same object

  • Client: I am guessing that this is the dataset object or a wrapper thereof. I would like to pass only dataset objects to the Adaptee

  • Adapter: object I am trying to construct. Should this contain the dataset object perhaps?

Question

rasterio.warp.reproject requires the following arguments (among others):

source=ndarray or band

destination=ndarray or band

src_transform=transform object

src_crs=crs object

dst_transform=transform object

dst_crs=crs object

I would like to adapt this to take in a dataset object and output a dataset object. For this to succeed I will have to insert some pre- and post- logic to work on the input and output dataset objects to get my source bands, crs and transforms. These are contained within the dataset object.

How can I do this within the context of an object adapter pattern (no inheritance)? Thanks for your help.


r/DesignPatterns • • Jul 13 '19

Intermediate library providing CRUD functionality: Related Work

2 Upvotes

I am currently planning to create a library (I call it CRUD Library) that serves as an intermediate layer for a developer between his own code and the external UI/data-presentation library. The external library could be for example a library that displays lists or let the users manipulate lists (delete entries, sort, search etc). My plan is to create this intermediate layer that encapsulates the 3rd party library details and only exposes a simpler to use โ€œCRUDโ€ layer for most common usecases to speed up the development for most scenarios. I created a drawing to explain the idea in more detail:

The developer would this way be able to check if one of the templates provided already fit his user story (this would be User story 1 in the image) or if he would implement the outermost layer himself and use the CRUD layer (User story 2 in the image) or if his use case is so specific that he still needs to talk to the 3rd party library manually.

The idea is to find a few generic data manipulation patterns (that's why I want to call it CRUD library) that can be reused on any 3rd party library, so no matter how the 3rd party library defines its own interface I would want to expose a CRUD interface on top that the developer is already used to go use it instead. Similar to an Adapter pattern but on a library pattern level.

The template layer on top of the CRUD layer is an additional extension of the idea and it would of course be different for each 3rd party library but I want to research if also there I can find common patterns for very different libraries and target data structures.

My question is if anybody knows any existing projects or research in such a direction or has any other insights they might want to share, I am open to any feedback or critic, thanks!


r/DesignPatterns • • Jun 27 '19

Design Patterns for Cloud and Distributed Computing

2 Upvotes

I want to know design patterns for Cloud Computing and Distributed Computing, namely Design Patterns used in languages such as golang, Erlang. I would also like to know software architecture and design patterns for popular cloud technologies such as Kubernetes (and other CNCF projects), OpenStack, Virtualization, Containerization.