TAILIEUCHUNG - Enterprise Java and UML 2nd Edition PHẦN 6

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

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.