Aggregation


Dependency vs. Association

A Java program built from many classes will manifest several types of interclass relationships. Before continuing with this chapter you must be clear in your understanding of the terms dependency and association.

A dependency is a relationship between two classes in which a change made to one class will have an affect on the behavior of the class or classes that depend on it. For example, if you have two classes, class A and class B, and class A depends upon the behavior of class B in a way that a change to class B will affect class A, then class A has a dependency on class B. If you use a class in your program and write code that calls one or more of that class’s interface methods then your code is dependent upon that class. If its interface methods change your code might break. If the behavior of those methods change your program’s behavior will change as well.

All but the most trivial Java programs you write will be chock full of dependency relationships between your classes and, at the very least, the classes you use in your programs that are supplied by the Java Platform API.

An association is a relationship between two classes that denotes a connection between those classes. An association implies a peer-to-peer relationship between the classes that participate in the association. If you have two classes, class A and class B, and there is an association between class A and class B, then class A and class B are linked together at the same level of importance. They may each depend on the other and the link between them will be navigable in one, or perhaps two, directions.

An aggregation is a special type of association and is discussed in detail in the following section.




Java For Artists(c) The Art, Philosophy, and Science of Object-Oriented Programming
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504052
EAN: 2147483647
Year: 2007
Pages: 452

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net