java 内聚_java – 内聚和解耦

从Aaron的文章是很好的理解,也是我建议你阅读maning

Spring in Action书,他们给了很好的例子,如何Spring解决这个问题,它一定会提高你的理解。

编辑:

我来到这个在这本伟大的书叫Growing面向对象软件由测试指导:

耦合:

Elements are coupled if a change in

one forces a change in the other. For

example, if two classes inherit from a

common parent, then a change in one

class might require a change in the

other. Think of a combo audio system:

It’s tightly coupled because if we

want to change from analog to digital

radio, we must rebuild the whole

system. If we assemble a system from

separates, it would have low coupling

and we could just swap out the

receiver. “Loosely” coupled features

(i.e., those with low coupling) are

easier to maintain.

凝聚:

An element’s cohesion is a measure of whether its responsibilities form a meaningful unit. For example, a class that parses both dates and URLs is not coherent, because they’re unrelated concepts. Think of a machine that washes both clothes and dishes—it’s unlikely to do both well.2 At the other extreme, a class that parses only the punctuation in a URL is unlikely to be coherent, because it doesn’t represent a whole concept. To get anything done, the programmer will have to find other parsers for protocol, host, resource, and so on. Features with “high” coherence are easier to maintain.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值