2
votes

Are all design patterns described in GOF programming language independent? By programming language I mean any OO language.

I see people talking about PHP design patterns, C++ design patterns and so on. I guess by prefixing the programming language they specifically mean about the design patterns applicable for that specific language by making use of features unique to that specific language.

This made me wonder about the GOF patterns. Do all patterns in the book guaranteed to be applicable in any OO language? In other words, if I master the design patterns in GOF book using Java, and then if I had to use another OO language, Can I still implement all those patterns?

1
While yeah they should be language-agnostic they are a sign of that something is wrong with the abstractions in those languages (you see: you need the patterns just because you cannot express them in code)Random Dev

1 Answers

13
votes

Yes, they're supposed to be prose descriptions for common object-oriented programming problems. They don't depend on any language.

The proof is that the examples in the book that came out in 1995 were in C++ and Smalltalk, the two leading object-oriented languages of the day. They've since been translated and adapted by Java and C#, two languages that didn't even exist when the book was first published.

"Guaranteed" is too strong a word.

The one thing you want to avoid is "small boy with a hammer" syndrome. It happens to everyone after reading that book for the first time: they run around looking for ways to implement patterns whether they fit or not.

You should aim to write the clearest, DRYest, most readable code you can. Don't worry about patterns.

I've read that functional programmers scoff at the design patterns, saying that they are band-aids on defects in object oriented programming that don't exist in other languages. I'm not a good enough functional programmer to know if this is true.