50 Visual Glossary Java Example shows how the association relationship shown in Figure between Person and Vehicle can be implemented in Java. Each reference to a Vehicle object is kept in a Vector. The Person class simply holds the vehicles for a person. import .*; /** * The Person class contains all data and logic for a person * in the system. */ public class Person { public Vector vehicles = new Vector(); /** Adds a vehicle to this person. */ public void addVehicle(Vehicle v) { (v); } } Guidelines Association is the default long-term relationship between objects. If you are in doubt as to. | 50 Visual Glossary Java Example shows how the association relationship shown in Figure between Person and Vehicle can be implemented in Java. Each reference to a Vehicle object is kept in a Vector. The Person class simply holds the vehicles for a person. import . The Person class contains all data and logic for a person in the system. public class Person public Vector vehicles new Vector Adds a vehicle to this person. public void addVehicle Vehicle v v Guidelines Association is the default long-term relationship between objects. If you are in doubt as to which long-term relationship to use use association. Aggregation Aggregation indicates a long-term relationship with the additional restriction that some of the objects are part of another object. It is this whole-part nature of the relationship that distinguishes aggregation from association. UML Example To continue the example each Vehicle object may contain zero or one Engine objects. There is a clear whole-part relationship as the engine is part of the car or truck. Figure shows a modified association from Vehicle to Engine with the hollow diamond at the Vehicle indicating aggregation. The hollow diamond is always drawn next to the enclosing whole. Visual Glossary 51 Figure Aggregation example. Java Example The following Java files show how the UML model in Figure can be implemented in Java. Only the files that have changed from the previous running example are shown. Vehicle no longer determines whether it is running or not. Instead this behavior is delegated to an Engine object. The Vehicle class contains the data and behavior that is common to all Vehicles. public abstract class Vehicle private Engine engine Sets the engine public void setEngine Engine e e Answers the noise made when the Vehicle goes. Must be overridden by all concrete implementations of Vehicle. 52 Visual Glossary public abstract String go