官术网_书友最值得收藏!

Common misunderstandings about design patterns

There are a few misunderstandings about design patterns. One misunderstanding is that design patterns should be used right from the start when writing code. It is not unusual to see developers struggling with which pattern they should use in their code, even if they haven't first tried to solve the problem in their own way [j.mp/prsedp], [j.mp/stedp].

Not only is this wrong, but it is also against the nature of design patterns. Design patterns are discovered (in contrast to invented) as better solutions over existing solutions. If you have no existing solution, it doesn't make sense to look for a better one. Just go ahead and use your skills to solve your problem as best as you think. If your code reviewers have no objections and through time you see that your solution is smart and flexible enough, it means that you don't need to waste your time on struggling about which pattern to use. You might have even discovered a better design pattern than the existing one. Who knows? The point is do not limit your creativity in favor of forcing yourself to use existing design patterns.

A second misunderstanding is that design patterns should be used everywhere. This results in creating complex solutions with unnecessary interfaces and hierarchies, where a simpler and straightforward solution would be sufficient. Do no treat design patterns as a panacea because they are not. They must be used only if there is proof that your existing code "smells", and is hard to extend and maintain. Try thinking in terms of you aren't gonna need it (YAGNI [j.mp/c2yagni]) and Keep it simple stupid (KISS [j.mp/wikikis]). Using design patterns everywhere is as evil as premature optimization [j.mp/c2pro].

主站蜘蛛池模板: 呼和浩特市| 会昌县| 民和| 昭觉县| 涿州市| 富平县| 咸阳市| 昌吉市| 英吉沙县| 大竹县| 远安县| 哈巴河县| 潼关县| 民权县| 岢岚县| 炉霍县| 汨罗市| 辽阳市| 房产| 大姚县| 仁化县| 靖安县| 瓮安县| 临沂市| 葵青区| 海安县| 桂平市| 开江县| 吴忠市| 扎兰屯市| 成都市| 吴堡县| 益阳市| 乐业县| 南部县| 汾西县| 顺义区| 新乐市| 台前县| 天等县| 蓬溪县|