Samuel's Weblog

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  7 随笔 :: 2 文章 :: 9 评论 :: 0 Trackbacks

2007年4月26日 #

最近在审查(review)代码时,常常发现一大堆代码充满了各种bad smell.即使工作了三五年的同事,也不会例外.沟通时往往发现他们对OO的理解只是表现出简单的概念理解.对OO的一些原则不甚了解,或者写代码也是跟着感觉走.

我最初做开发的时候也是跟着感觉走,初次听到OCP如天外来物.使用Java或C#不代表你就是在做OO开发,熟练使用OO语言不代表已经对OO非常了解.感谢Uncle Bob的经典巨著<Agile Software Development>,坚持阅读的习惯让我接触并努力理解OO原则.一旦对这些原则有了深入的认识,写代码时就已经从更高的角度来分析问题,解决问题,力争写出优雅的代码.

我对OO的了解也不算多深刻,只在这里抛砖引玉.因为原则比较多,用一个系列来介绍会让大家更容易沟通.

同时,原则是死的,人是活的,不要被这些原则束缚,有一些原则在特定的情况下才会有效.

Single Choice Principle(SCP)
所有的判断只在一处进行.违反此原则的典型情况是不同的方法中充斥着相同的if ... else ...或类似的语句.

Linguistic Modular Units

Few Interfaces

Small Interfaces

Explicit Interfaces

Behavioral Completeness
一个完整的类必须包含完整的方法.如果类没有完成它的职责,或者没有完成其父类需要完成的工作,那么它就是不完整的类.

Law Of Demeter
只与直接协作的类交互.

The Principle of Essential Representation(PER)
类应该包含而且只包含其本质的定义和表现,与SRP比较接近.

Single Responsibility Principle(SRP)
一个类只承担一项职责,只能有一个发生变化的理由,那就是它的职责变化了.

Open-Colse Principle(OCP)
类应该对扩展是开放的,对修改是封闭的.

Liskov Substitution (LSP)
子类必须可以替换父类.

Dependency-Inversion Principles(DIP)
高层应该不依赖于低层,双方都应该依赖于抽象.抽象不依赖于细节,细节应该依赖于抽象.

Interface Segregation Principles(ISP)
接口属于客户程序.

---------------------------------
Reuse Release Equivalence Principle(REP)
重用的粒度等于发布的粒度.

Common Reuse Principle(CRP)
包中的类应该是共同重用的.

Common Closure Principle(CCP)
包中的类对同一类变化共同封闭的,一个类发生变化,可能所有的类都要发生变化.

---------------------------------
Acyclic Dependencies Principle(ADP)
包之间的依赖结构不应该存在环依赖.

Stable Dependencies Principle (SDP)
包应该依赖于比它更稳定的包.

Stable Abstractions Principle(SAP)
包的稳定程度与抽象程度成正比,越抽象的包越稳定.

---------------------------------
开发时应该避免的bad design smell:
僵化(Rigidity) 一处变化会影响系统中的很多地方.
脆弱(Fragility) 一处变化会影响系统中不应该被影响的地方.
牢固(Immobility) 很难被重用.

还有一些原则可能被遗漏掉,如果你发现了,请及时提醒我.

 更多内容在另一博客http://samuelray.javaeye.com.
posted @ 2008-03-14 09:55 SamuelRay 阅读(1831) | 评论 (8)编辑 收藏

1. You make me sick! 你真让我恶心!
2. What’s wrong with you? 你怎么回事?
3. I’m very disappointed. 真让我失望。
5. You’re a jerk! 你是个废物/混球!
6. Don’t talk to me like that! 别那样和我说话!
7. Who do you think you are? 你以为你是谁?
8. What’s your problem? 你怎么回事啊?
9. I hate you! 我讨厌你!
10. I don’t want to see your face! 我不愿再见到你!
11. You’re crazy! 你疯了!
12. Are you insane/crazy/out of your mind? 你疯了吗?
13. Don’t bother me. 别烦我。

14. Knock it off. 少来这一套。
15. Get out of my face. 从我面前消失!
16. Leave me alone. 走开。
17. Get lost.滚开!
18. Take a hike! 哪儿凉快哪儿歇着去吧。
19. You piss me off. 你气死我了。
20. It’s none of your business. 关你屁事!
21. What’s the meaning of this? 这是什么意思?
22. How dare you! 你敢!
23. Cut it out. 省省吧。
24. You stupid jerk! 你这蠢*!
25. You have a lot of nerve. 脸皮真厚。
26. I’m fed up. 我厌倦了。
27. I can’t take it anymore. 我受不了了!(李阳老师常用)
28. I’ve had enough of your garbage. 我听腻了你的废话。
29. Shut up! 闭嘴!
30. What do you want? 你想怎么样?
31. Do you know what time it is? 你知道现在都几点吗?
32. What were you thinking? 你脑子进水啊?
33. How can you say that? 你怎么可以这样说?
34. Who says? 谁说的?
35. That’s what you think! 那才是你脑子里想的!

36. Don’t look at me like that. 别那样看着我。
37. What did you say? 你说什么?
38. You are out of your mind. 你脑子有毛病!
39. You make me so mad.你气死我了啦。
40. Drop dead. 去死吧!
41. Don’t give me your shit. 别跟我胡扯。
42. Don’t give me your excuses/ No more excuses. 别找借口。
43. Nonsense! 鬼话!
44. You’re a pain in the ass. 你这讨厌鬼。
45. You’re an asshole. 你这缺德鬼。

46. You asked for it. 你自找的。
47. Get over yourself. 别自以为是。
48. You’re nothing to me. 你对我什么都不是。
49. It’s not my fault. 不是我的错。
50. You look guilty. 你看上去心虚。
51. I can’t help it. 我没办法。
52. That’s your problem. 那是你的问题。
53. I don’t want to hear it. 我不想听!
54. Get off my back. 少跟我罗嗦。
55. Give me a break. 饶了我吧。

56. Who do you think you’re talking to? 你以为你在跟谁说话?
57. Look at this mess! 看看这烂摊子!
58. You’re so careless. 你真粗心。
59. Why on earth didn’t you tell me the truth? 你到底为什么不跟我说实话?
60. I’m about to explode! 我肺都快要气炸了!
61. What a stupid idiot! 真是白痴一个!
62. I’m not going to put up with this! 我再也受不了啦!
63. I never want to see your face again! 我再也不要见到你!
64. That’s terrible. 真糟糕!
65. Just look at what you’ve done! 看看你都做了些什么!

66. I wish I had never met you. 我真后悔这辈子遇到你!
67. You’re a disgrace. 你真丢人!
68. I’ll never forgive you! 我永远都不会饶恕你!
69. Don’t nag me! 别在我面前唠叨!
70. I’m sick of it. 我都腻了。
71. Don’t you dare come back again! 你敢再回来!
72. Stop screwing/ fooling/ messing around! 别鬼混了!
73. Mind your own business! 管好你自己的事!
74. You’re just a good for nothing bum! 你真是一个废物!/ 你一无是处!
75. You’ve gone too far! 你太过分了!

76. I loathe you! 我讨厌你!
77. I detest you! 我恨你!
78. Get the hell out of here! 滚开!
79. Don’t be that way! 别那样!
80. Can’t you do anything right? 成事不足,败事有余。

81. You’re impossible. 你真不可救药。
82. Don’t touch me! 别碰我!
83. Get away from me! 离我远一点儿!
84. Get out of my life. 我不愿再见到你。/ 从我的生活中消失吧。
85. You’re a joke! 你真是一个小丑!

86. Don’t give me your attitude. 别跟我摆架子。
87. You’ll be sorry. 你会后悔的。
88. We’re through. 我们完了!
89. Look at the mess you’ve made! 你搞得一团糟!
90. You’ve ruined everything. 全都让你搞砸了。
91. I can’t believe your never. 你好大的胆子!
92. You’re away too far. 你太过分了。
93. I can’t take you any more! 我再也受不了你啦!
94. I’m telling you for the last time! 我最后再告诉你一次!
95. I could kill you! 我宰了你!

96. That’s the stupidest thing I’ve ever heard! 那是我听到的最愚蠢的事!  (比尔·盖茨常用)
97. I can’t believe a word you say. 我才不信你呢!
98. You never tell the truth! 你从来就不说实话!
99. Don’t push me ! 别逼我!
100. Enough is enough! 够了够了!

posted @ 2007-04-26 15:40 SamuelRay 阅读(356) | 评论 (0)编辑 收藏