Wiki Home

Relationship Heuristics


Namespace: Wiki
A place to list and discuss rules of thumb relating to object relationships.
See: Riel, A (1996), Object Oriented Design Heuristics, ISBN 020163385X.
  • When given a choice in object-oriented design between a Containment Relationship and an Association Relationship, choose the containment relationship. Related to this, see UML Composition Vs Aggregation
  • Minimize the number of classes with which another class collaborates.
  • Minimize the number of messages sent between a class and its collaborators.
  • Minimize the amount of collaboration between a class and its collaborators.
  • If a class contains objects of another class, then the containing class should be sending messages to the contained class. In VFP this is a very "soft" (and arguably inapplicable) heuristic since all objects have implicit This.parent, ThisForm and ThisFormSet. Thus you can have inside-out messaging with no coupling costs.
  • Most of the methods defined on a class should be using most of the data members most of the time.
  • Classes should not contain more objects than a developer can fit into his short-term memory.
  • Distribute system intelligence vertically down narrow and deep containment hierarchies.
  • When implementing SemanticConstraints, it is best to implement them in terms of the class definition.
  • When implementing semantic constraints in the constructor of a class, place the constraint test in the constructor as far down a containment hierarchy as the domain allows.
  • The semantic information on which a constraint is based is best decentralized in a central, third-party object when that information is volatile.
  • The semantic information on which a constraint is based is best decentralized among classes involved in the constraint when that information is stable.
  • A class must know what it contains, but it should never know who contains it.
  • Objects that share lexical scope should not have UsesRelationships between them.
    Category OOPrinciples Category Class Design, other Object Oriented Heuristics
  • ( Topic last updated: 1999.08.28 02:02:56 AM )