Grady Butch in "Object-Oriented Analysis and Design":
“The idea of ​​cohesion also comes from structured design. Simply put, cohesion measures the degree of connectivity between elements of a single module (and for object-oriented design, one class or object). The least desirable form of cohesion is a coincidence in which absolutely unrelated abstractions are thrown into one class or module, for example, consider a class containing abstractions of dogs and spacecraft whose behavior is completely unrelated.The most desirable form of linkage is a functional Very, in which elements of the class or module work together to provide a well-bounded behavior. Thus, the class Dog is functionally united, if it covers the semantics of the dog, all dogs and nothing but the dog. "
Provide the Dog with the Client in the example above, and that might be a little clearer. Thus, the goal is simply to aim at functional cohesion and move as far away from coincidence as possible. Depending on your abstractions, this may be simple or may require some refactoring.
The combination of notes applies in the same way as to a “module” than to a single class, i.e. group of classes working together. Thus, in this case, the Customer and Order classes still have decent cohesion, because they have such a strong relationship, customers create orders, orders belong to customers.
Marcus Fowler says it would be more convenient for him to call this “Demon Offer” (see the article
Mocks are not stubs ):
"Uterus testers are trying to talk more about avoiding train breaks - a chain of getThis (). GetThat (). GetTheOther () style chains. Avoiding a chain of methods is also known as Demeter’s law. Odor, the opposite problem of middle-aged objects, inflated by methods Forwarding is also a smell. (I always felt that I would be more comfortable with the Demeter Act if it was called Demeter Offer .) "
That I perfectly understand where I come from: it is quite acceptable and often it is necessary to have a lower level of cohesion than strict observance of the "law" may be required. Avoid matching cohesion and focus on functional grip, but do not suspend it in settings where it is necessary for a more natural combination with the abstraction of your design.
Ash 03 Oct '08 at 5:47 2008-10-03 05:47
source share