我在某处看到过这个公式:
技能=问题的复杂性/解决方案的复杂性 http://img39.imageshack.us/img39/1586/whatisskill.png
换句话说,它需要技巧来为复杂问题创建简单的解决方案。如果有人故意设计并以复杂的过度设计解决方案为荣,那么他在不知不觉中无能。
就个人而言,帮助我保持设计简单的是 TDD 循环。首先编写一个测试来指定您要达到的目标,然后生成“可能工作的最简单的东西”。并且时不时地反思一下你制作的东西,并思考如何让它变得更简单。
Never build extra flexibility and abstraction layers into the system, until it is required by something that you have now. Changing the code is easy, when you have a good unit test suite, so you can add those abstraction layers later, when the need arises, if it ever arises. Otherwise, "you ain't gonna need it".
Some symptoms of too complex design are when writing tests is complicated. If the tests require a long setup code, maybe you have too many dependencies or in some other way too much complexity. If you run into concurrency bugs, then maybe you should think about how to design the system so that concurrency is restricted to the absolute minimum number of classes. Maybe use a message-passing architecture, such as the Actor model, and make practically every component single-threaded, even though the system as a whole is multi-threaded.