Posted on 2005-01-25 23:25
Blue Kong 阅读(516)
评论(0) 编辑 收藏 所属分类:
Java World
去年用英文写BLOG时的帖子,自己转自己,叫自转 :P
The Open Closed Principle (OCP) states that we should be able to add new features to our system without having to modify our set of preexisting classes. The following Class Diagram shows that how to design the relationship between the classes so as to adhere the OCP under certain circumstance:
The User class has a relationship to the UserType abstract class. The simple sample design shows that it adheres one of the tenets of OCP:“to reduce the coupling between classes to the abstract level. Instead of creating relationships between two concrete classes, we create relationships between a concrete and an abstract class ,or in Java, between a concrete class and an interface.
Principles should be reminded again and again. ^_^