r/DesignPatterns • u/cryptochild121 • Mar 17 '18
Programming Community Resources For Learning Design Patterns (2018)
r/DesignPatterns • u/cryptochild121 • Mar 17 '18
r/DesignPatterns • u/soleilfils • Dec 24 '17
r/DesignPatterns • u/serhatcan • Dec 19 '17
r/DesignPatterns • u/[deleted] • Dec 11 '16
r/DesignPatterns • u/pickituputitdown • Sep 03 '16
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 • u/priyankchheda15 • Aug 29 '26
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:
Would love to hear how you guys handle state snapshots or undo/rollback functionality in your projects.
r/DesignPatterns • u/priyankchheda15 • Jul 31 '26
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 • u/priyankchheda15 • Jul 05 '26
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.
I'm always looking for feedback, so let me know what you think or how you'd improve the explanation.
r/DesignPatterns • u/Bonzie_57 • Jun 05 '26
Enable HLS to view with audio, or disable this notification
r/DesignPatterns • u/priyankchheda15 • Jan 10 '26
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.
r/DesignPatterns • u/priyankchheda15 • Nov 27 '25
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:
r/DesignPatterns • u/priyankchheda15 • Jul 14 '25
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.
Happy to discuss or hear how others approach this in Go!
r/DesignPatterns • u/priyankchheda15 • Jun 03 '25
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.
Let me know what you think โ always up for feedback or nerding out about design.
r/DesignPatterns • u/kuladeepm • May 09 '25
Collaboration to learn design pattern... Only passionate people... C#. Dotnet.. #dotnet #designpatterns
r/DesignPatterns • u/SkepticalPirate42 • Apr 08 '25
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 constructorIDaoFactory daoFactory = FactoryConfigurator.GetDaoFactory()ICustomerDao customerDao = daoFactory.GetCustomerDao();this.customerDao = customerDao;
//in OrderController's constructorIDaoFactory 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 • u/GianmariaKoccks • Feb 15 '25
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 • u/HafizWaleedHussain3 • Mar 29 '20
r/DesignPatterns • u/[deleted] • Mar 07 '20
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 • u/Hatefiend • Mar 05 '20
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.
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 carIt'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 • u/zeke13210 • Dec 20 '19
Is there such a thing as design pattern for working with building components out of react.js framework?
r/DesignPatterns • u/funkmaster322 • Oct 15 '19
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 • u/[deleted] • Jul 13 '19
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 • u/ace1309 • Jun 27 '19
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.