Đang chuẩn bị liên kết để tải về tài liệu:
Enterprise Java and UML 2nd Edition PHẦN 6

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

50 Visual Glossary Java Example Person.java shows how the association relationship shown in Figure VG.3 between Person and Vehicle can be implemented in Java. Each reference to a Vehicle object is kept in a Vector. Person.java The Person class simply holds the vehicles for a person. import java.util.*; /** * 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) { this.vehicles.addElement(v); } } Guidelines Association is the default long-term relationship between objects. If you are in doubt as to. | 50 Visual Glossary Java Example Person.java shows how the association relationship shown in Figure VG.3 between Person and Vehicle can be implemented in Java. Each reference to a Vehicle object is kept in a Vector. Person.java The Person class simply holds the vehicles for a person. import java.util. 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 this.vehicles.addElement 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 VG.4 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 VG.4 Aggregation example. Java Example The following Java files show how the UML model in Figure VG.4 can be implemented in Java. Only the files that have changed from the previous running example are shown. Vehicle.java 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 this.engine 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

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.