In: Computer Science
Give a UML example illustrating aggregation. Include classes, fields, methods, instance fields etc. Use one supper class and two sub classes. Include pseudo code for at least one method of each class. (Put your name on every piece of paper). Also explain the whole part relationship and if this is a deep copy or a shallow copy?
PROGRAMMING LANGUAGE - JAVA (IF NEEDED)
PLEASE ANSWER IT ASAP. THANKS IN ADVANCE!
Description : Aggregation is a special form of association. It is a relationship between two classes like association, however its a directional association, which means it is strictly a one way association. It represents a HAS-A relationship.
2. For example consider three classes Student
class
and Address
class. Every student has an address so the
relationship between student and address is a Has-A relationship.
But if you consider its vice versa then it would not make any sense
as an Address
doesn’t need to have a
Student
necessarily.
Same with the class collages ,Every collage has an address so the relationship between collage and address is a Has-A relationship.
we need AggregationTo maintain code re-usability.
Student Has-A Address (Has-a relationship between student and address) College Has-A Address (Has-a relationship between college and address)
UMAL diagram forAggregation
pseudo code:
class Address { int streetNum; String city; String state; String country; Address(int street, String c, String st, String coun) { this.streetNum=street; this.city =c; this.state = st; this.country = coun; } } class StudentClass { int rollNum; String studentName; //Creating HAS-A relationship with Address class Address studentAddr; StudentClass(int roll, String name, Address addr){ this.rollNum=roll; this.studentName=name; this.studentAddr = addr; } ... } class College { String collegeName; //Creating HAS-A relationship with Address class Address collegeAddr; College(String name, Address addr){ this.collegeName = name; this.collegeAddr = addr; } ... }