Java problem Give a UML example illustrating aggregation Inc

Java problem 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. Also explain the whole-part relationship and if this is a deep copy or a shallow copy?

Solution

Aggregation is a connection between two classes that is best described as a \"has-a\" and \"entire/part\" connection Let Subject be the super class and Student, Instructor be the two sub classes .

This is an example of aggregation because student has a subject and Instructor has a subject (i,e has a relationship holds)

For example, imagine a Student class that stores information regarding individual students at a school.

Now let\'s say there is a Subject class that holds the information about a particular subject (e.g., history, geography).

If the Student class is defined to have a Subject object then it can be said that the Student object has-a Subject object.

The Subject object also makes up part-of the Student object, after all there is no student with no subject to study.

The Student object is therefore the holder of the Subject object.

Similarly for instructor

Code:

public class Subject {

private String name;

public void setName

(String name)

{ this.name = name;

}

public String getName() {

return name;

}

}

public class Student {

private String id;

private String name;

private float cg;

public void setCg(float cg) { this.cg = cg; }

public String getCg() { return cg; }

}

public class Student {

private String InstrId;

private String name;

private int age;

public void setAge(int age) { this.age = age; }

public String getAge() { return age; } }

 Java problem Give a UML example illustrating aggregation. Include classes, fields, methods, instance fields, etc. Use one supper class and two sub classes. Inc
 Java problem Give a UML example illustrating aggregation. Include classes, fields, methods, instance fields, etc. Use one supper class and two sub classes. Inc

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site