t**r 发帖数: 3428 | 1 No design patterns are necessary. In any language.
I tend to come across a lot of code written by people who read up on design
patterns and than think they should use them all over the place and the
result is the actual code gets buried under tons of interfaces, wrappers and
layers and pretty hard to read. That's a wrong approach to design patterns.
Design patterns exist so that you have a repertoire of useful idioms handy
when you come across a problem. But you should never apply any pattern
before you identify the problem. Keep It Simple Stupid should always be the
superior governing principle.
It also helps to think of design patterns as a concept to think about the
problem rather than specific boilerplate code to write. And about much of
the boilerplate as workaround to Java lacking free functions and standard
function objects that you use in most other languages that have them (like
Python, C#, C++ etc).
I might say that I have a visitor pattern, but in any language with first
class functions it will be just function taking function. Instead of factory
class I usually have just factory function. I might say I have interface,
but than it's just a couple of methods marked with comment, because there
wouldn't be any other implementation (of course in python interface is
always just comment, because it's duck-typed). I still speak of the code as
using the pattern, because it's useful way to think about it, but don't
actually type in all the stuff until I really need it.
So learn all the patterns as concepts. And forget the specific
implementations. The implementation varies, and should vary, in real world
even in Java.
Jan Hudec | d*******r 发帖数: 3299 | | w***g 发帖数: 5958 | 3 打架的时候谁会记着一招一式叫什么名字。
design
and
patterns.
the
【在 t**r 的大作中提到】 : No design patterns are necessary. In any language. : I tend to come across a lot of code written by people who read up on design : patterns and than think they should use them all over the place and the : result is the actual code gets buried under tons of interfaces, wrappers and : layers and pretty hard to read. That's a wrong approach to design patterns. : Design patterns exist so that you have a repertoire of useful idioms handy : when you come across a problem. But you should never apply any pattern : before you identify the problem. Keep It Simple Stupid should always be the : superior governing principle. : It also helps to think of design patterns as a concept to think about the
|
|