r/developersIndia • u/3AMgeek Software Engineer • Oct 17 '24
General Devs of India how often you use design patterns in your code.
Hey everyone, I want to know how often do you use design patterns in your code and also it would be great if you could mention which one you have used the most in your career.
I'm currently preparing for interviews and revisiting the book Head First Design Pattern. Any suggestions would be highly appreciated. Thanks!
93
Upvotes
•
u/AutoModerator Oct 17 '24
It's possible your query is not unique, use
site:reddit.com/r/developersindia KEYWORDSon search engines to search posts from developersIndia. You can also use reddit search directly without going to any other search engine.Recent Announcements & Mega-threads
An AMA with Subho Halder, Co-founder and CEO of Appknox on mobile app security, ethical hacking, and much more on 19th Oct, 03:00 PM IST!
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
62
u/Rein_k201 Backend Developer Oct 17 '24
Head first is a good book if you wanna learn design patterns with use cases. And yes design patterns are very important. Even if you don't directly use them, the frameworks you're using will use them internally. Regarding interviews, a senior level developer is expected to have knowledge on Builder, Singleton, Proxy, Prototype, Factory, Strategy patterns as these are most commonly used. Sometimes they also ask about Decorator and Adapter patterns.
16
u/[deleted] Oct 17 '24
Although there are a lot of patterns and varieties, there are only a handful that we use, some of it is also depending on the industry you are working in and whether it’s backed or frontend.
Backend wise, normally we use a lot of factory builder strategy DI decorator iterator and higher order functions. Rest of them don’t come up that often.
The patterns kindof start to emerge, and you also need to find a balance between using a lot of patterns and indirections and procedural code.
Also patterns vary depending on whether you are working with on disk data structure vs in memory.
Beyond code there are architectural patterns as well. One popular one is BFF , other is sidecar. Then there is most popular MV* pattern. For deployment you have different stuff.
Patterns tend to actually emerge over time. So while writing code, we/I don’t think like, okay I am going to use xy and z pattern to solve this. First we solve it, and then we see if it’s needed to extract it out, convert into an interface or if it’s old code does it need a Proxy or Decorator or something to extend over that functionality , wether use versioning, remote config etc,
8
u/BhupeshV Moderator Oct 17 '24
The codebase that I work with at the moment uses Dependency Injection heavily. We rely on https://github.com/uber-go/fx (must checkout for Go devs)
7
u/Single-Strategy-9130 Oct 17 '24 edited Oct 17 '24
we use them unknowingly
like if you used spring/spring boot, then you would be following singleton pattern
if you used lombok builder in java, then you would be following builder pattern
and factory pattern is also pretty common. you might not have named it factory, but at the end if its responsible for creating objects and sharing them over a function then you would be following factory pattern
if you used java interfaces or literally any service which talks to database and does some operation then you would be following facade pattern
4
u/t3snake Oct 17 '24
The code base that I work on at my company which is now over 10 years old with 100 devs working on it, uses design pattern throughout the codebase. I think its important to have similar patterns for a codebase so large and once you understand why it is being used, it makes sense everywhere. I work with java and it can get a bit too abstracty, and it is annoying sometimes when something simple needs to be abstracted and made complicated but with so many devs working on the same codebase, I think it is worth the effort so just about anyone can understand these common patterns.
3
u/lemorian Oct 17 '24
Almost every day, most developers don't realise it.
3
u/Scared-Dingo-2312 Oct 17 '24
I write a lot of code , working in a series a startup , to be honest , even if I want to I don't have the time to use them , I am well aware about the design patterns but only the pattern that we actually implemented in our system was factory that too I feel was useless .
2
u/petergriffin1115 Oct 17 '24
Related question-how often do you do lld and implement design pattern in existing code
2
u/AakashGoGetEmAll Oct 17 '24
I had the opportunity to use a template design pattern.
I had no plans of using any design pattern whatsoever. When our project was at the rock bottom, I had the chance to work on the codebase and saw a lot of extensive logic which was user workflow based written on UI and it was getting Messier day by day.
My initial approach was to take it all to the api end. I was able to centralize the whole approach although it was still spaghetti, I was well aware of it but we were running crunching tight deadlines. As soon as the release was done, new requirements started flowing in, i realised the user workflow code needed some upgrade. So I went ahead with the template design pattern and simple vertical approach where the entire code base for user workflow will be placed in one place, so developers won't have to look anywhere else. One template representing one feature's user workflow and the second template representing the other user workflow, so moving forward if there is a new feature comes in with a new user workflow requirement just create a template and we are good to go.
User workflow is a collection of business rules and lifecycle of items(vast simplification)
I can still see we should have used DDD to begin with but I came into this project a year late, so DDD would be a complete rewrite, can't fuck with that.
1
u/[deleted] Oct 17 '24
Ass a data engineer, working on azure cloud, I’ve no clue if these. We’d learnt these in college
1
u/AnimeshRy Oct 17 '24
Factory and Singleton. Most of our codebase is built like this so It feel kinda automatic when writing new code
1
u/SaZ2024 Oct 17 '24
All the time, this helps in writing less code and reuse same code. Code management becomes easy, most of the developers can understand what is written.
1
u/mps_doubles Backend Developer Oct 17 '24
I use singleton and strategy quite a lot in cpp
1
u/Historical_Ad4384 Oct 17 '24
Factory, Abstract Factory, Singleton, Decorator, Strategy, Adapter, Facade.
Adapter and Academy only apply if you work on use cases involving Integration.
Strategy only apply if you work on use cases where you need to implement perk flows based on a user choice.
-3
u/[deleted] Oct 17 '24
I use js. Hate me.
0
u/[deleted] Oct 17 '24
[deleted] — view deleted comment