r/cpp • u/Keter_01 • Mar 30 '24
How often do you use design pattern?
Hey everyone! I'm currently a CS student and started recently to learn about design patterns (We apply it in Java but I figured since both are object oriented it could apply to cpp as well). I was just curious, how often will I use it? (I'm not planning to write a single line of Java willingly, let alone making it my job, that's why I ask on this sub)
6
Upvotes
2
u/Ill-Telephone-7926 Mar 31 '24
The GoF ‘Design Patterns’ book was written for C++, so they’re perfectly applicable. They became more popular vocabulary within the Java community, though. I put this down to Java’s more limited set of built-in abstractions at the time (in particular, the lack of function pointers) which required a profusion of named base classes to solve some classes of problems that had generic/template or language-level solutions in other languages.
Language agnostically, Design Patterns are spicy and a little goes a long way. If Pattern names are appearing in class names all over, the developers are probably thinking about them too much and likely over-applying them for my taste. I lean into simple concepts (e.g. regular values, invocables, standard containers) first and create class collaboration diagrams only when necessary to the problem. Abstractions should pay for themselves, not be the default.