您的位置:首页 > 编程语言 > Java开发

《Thinking in Java》的Java编程规范-设计思想

2014-04-14 14:02 316 查看
1, Elegance always pays off. 
  优雅总是物有所值。

-------ps:没有完全理解

2, First make it work, then make it fast. 
  先让程序可以工作,再让它跑得更快。 

--------这个也是做性能优化的一般 步骤

3,Remember
the "divide and conquer" principle. 
  记住“分而治之”原则。 

-------二分或N分是提高解决问题效率的一个好办法

4,Separate
the class creator from the class user(client programmer). 
  分隔类的创建者和使用者。(让类和接口容易被正确使用,不容易被错误使用) 

-----PS:应该是接口及其实现类的的应用吧,,

5,When
you create a class, attempt to make your names so clear that comments are unnecessary. 
  给类取名时,让类名一目了然到无需写注释。(Single Responsibility Principal) 

-----方便看和再看

6,
Your analysis and design must produce, at minimum, the classes in your system, their public interfaces, and their relationships to other classes, especially base classes. 

----ps:分析和设计必须至少体现在你的类与类之间的关系

7,
Automate everything. 
  一切自动化。(Ant, hudson) 

----设计模式

8,Write
the test code first(before you write the class) in order to verify that your class design is complete. 
  测试代码先行(先于类)来验证你的类设计是完善的。JUnit 

---JUnit

9,
All software design problems can be simplified by introducing an extra level of conceptual indirection. 
  所有的软件设计问题都可以通过引入一层间接层来简化。

----设计模式

10,
An indirection should have a meaning. 
  间接层需要有其存在的意义。

------封装变化

11,
Make classes as atomic as possible.Give each class a single, clear purpose. 
  尽量保持类的原子性,给每个类一个简单、清晰的目的。(Single Responsibility Principal) 

-------

12,Watch
for long argument list. 
  避免长参数列表.

-----可变参数或者用其他方法封装参数

13,
Don't repeat yourself. 
  代码不要重复。(DRY) 

14,
Watch for switch statements or chained if-else clauses. 
  避免复杂的switch语句和链式if-else语句。(使用polymorphism) 

-----接口多态,封装选择

15,
From a design standpoint, look for and separate things that change from things that stay the same. 
  站在设计的观点,找出、分离不变之物与常变之物。(封装变化) 

16,
Don't extends fundamental functionality by subclassing. 
  不要通过子类继承来扩展基本功能。(优先考虑组合,Decorator模式) 

----装饰者模式
17, Less is more. 
  少即是多。 

-----积少成多,还是不是很理解
18, Read your classes aloud to make sure they're logical. 
  大声朗读类名以确保它们是合情合理的。 

----检查他能能理解
19, When deciding between inheritance and composition, ask if you need to upcast to the base type. 
  在继承和组合之间难以取舍时,考虑该类是否需要向上转化为其基类。(是否需要使用polymorphism) 

-----考虑多态
20,Use fields for variation in value, and method overriding fro variation in behavior. 
  值差异用域覆盖,行为差异用方法覆盖。 
------
21, Watch for overloading. 
  避免重载.(使用好的方法名) 
   
22, Use exception hierarchies. 
  使用层次化的异常。 

------不理解
23, Sometimes simple aggregation does the job. 
  有时简单的组合就能解决问题。 
-----
24, Consider the perspective of the client programmer and the person maintaining the code. 
  从client端程序员和维护代码的人角度考虑问题。(让类和接口容易被正确使用,不容易被错误使用) 
   
25, Watch out for "giant object syndrome". 
  避免“巨型对象综合症”。(运用SRP分解对象泥团) 
   
26, If you must do something ugly, at least localize the ugliness inside a class. 
  如果逼不得已必须写一些丑陋的代码,把这些代码局限在一个类中。 

---方便管理
27, If you must do something nonportable, make an abstraction for that service and localize it within a class. 
   如果必须做一些不可移植的行为或服务,那么就做一个抽象来本地化

------暂时没有用到
28, Objects should not simply hold some data. 
  对象不应仅仅只拥有数据。还需要有methods。 
----
29, Choose composition first when creating new classes from existing classes. 
  从已有类中创建新类时,优先考虑组合。 

30, Use inheritance and method overriding to express differences in behavior, and fields to express variations in state. 
  行为变化用继承和方法覆盖搞定,变量状态变化用域表示。(State模式) 

----重复了
31, Watch out for variance. 
  考虑变化。(使用接口,抽象类) 
   
32, Watch out for limitation during inheritance. 
  当心继承的局限性。(类层次过多、Java单继承) 
   
33, Use design patterns to eliminate "naked functionality". 

使用设计模式,避免“裸方法”
34, Watch out for "analysis paralysis". 
  避免“分析瘫痪”。(避免过度分析,先快速做出原型) 
   
35, When you think you've got a good analysis, design, or implementation, do a walkthrough. 
  当你认为你有一个好的分析、设计或是实现时,演练一下。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息