- Mastering Python Design Patterns
- Sakis Kasampalis
- 287字
- 2021-08-06 19:21:40
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].
- SQL Server 從入門到項目實踐(超值版)
- 深入淺出數據科學:Python編程
- Rust實戰
- 零基礎學Scratch少兒編程:小學課本中的Scratch創意編程
- Python高級編程
- Python零基礎快樂學習之旅(K12實戰訓練)
- Java程序設計與實踐教程(第2版)
- Securing WebLogic Server 12c
- 琢石成器:Windows環境下32位匯編語言程序設計
- Python數據結構與算法(視頻教學版)
- Linux:Embedded Development
- 大數據分析與應用實戰:統計機器學習之數據導向編程
- Deep Learning with R Cookbook
- Java并發編程:核心方法與框架
- 網絡數據采集技術:Java網絡爬蟲實戰