Are Gang of four design patterns Programming language independent?
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?
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.
链接地址: http://www.djcxy.com/p/42886.html上一篇: ConstraintViolationException VS DataIntegrityViolationException
下一篇: 是四种设计模式的纲要编程语言是独立的吗?