准备OCJP的过程中,屡屡封装良好,松耦合,高聚合提到这三个概念...我暂时没有找到一个定义,自己粗浅地理解如下:
麻烦哪位高手,能否给补充一个定义?谢谢!well encapsulation
1)成员变量、方法private
2)对外提供publicloose coupling
一个类的修改不影响其它类
high cohesion
一个类只完成一件事javaencapsulationcouplingcohesion

解决方案 »

  1.   

    楼主所说的“封装良好,松耦合,高聚合”即所谓的编程思想一般到后面的大神们经常会提起的。像《effective java》那么多条的建议基本上离不开这些内容的。很多编程神作到后面都是讲思想的,像《算法导论》基本上都是用数学在解决问题,用的还是伪代码(美曰其名不为单一编程语言束缚),《重构改善代码的既有设计》《程序员修炼之道》等等。
    对于思想,当然是抓住“面向对象(Object Oriented)”,像个正常人去考虑问题。
    封装良好:隐藏对象的属性和实现细节,仅对外公开借口,并且控制访问级别(深藏功与名)
    松耦合:耦合指各个模块之前的关联程度。
    高聚合:聚合是指一个模块内部各个部分之间的关联程度
      

  2.   

    上传点所谓的定义Encapsulation is the OO principle most closely associated with hiding a class’s implementation details.Coupling is the OO principle most closely associated with making sure classes know about
    other classes only through their APIs.Cohesion is the OO principle most closely associated with making sure a class is designed
    with a single, well-focused purpose.Polymorphism is the OO principle most closely associated with allowing a single object to be
    seen as having many types.