I am trying to implement an enrollment organizer for a university but I would ask how to implement the aggregation relationship in Java.
this relationship exist for academicStaff class and the supervisor class in which the academicStaff (e.g prof.) can be a supervisor to multiple courses in a specific semester.
I think that I should make a list of supervisors in academicStaf class and an instance of acadmicStaff in the supervisor class.
so I need help to know the best way to implement this relationship.
thx in advance.

Edited by creative_m: n/a

5 Years
Discussion Span
Last Post by JamesCherrill

In general, if there is an aggregation relationship "an A has-many Bs" then you can use any member of the Collection hierarchy to hold multiple instances of B as an instance variable of A.
A simple ArrayList<B> is the most obvious choice, but if you want to access those Bs by, for example, their names, you could instead use a HashMap<String, B> to give you that access as well.
Holding the A as an instance variable in B is strictly speaking redundant, but in the vast majority of cases you would do exactly that because the code is simpler and faster.
It's hard to say anything more specific without a lot more info on your design criteria, volumes etc.

Edited by JamesCherrill: n/a


Holding the A as an instance variable in B is strictly speaking redundant

can you explain that please.

basically,there are no constraints on volume or other resources.
My design looks like this :
aggregation between AcadmicStaff and Supervisor (1 to *)
aggregation between Course and Supervisor (1 to *)
aggregation between semester and Supervisor (1 to *)
aggregation between Student and Enrollment (1 to *)
aggregation between course and Enrollment (1 to *)

I think maybe there is a better design but I am restricted to this one.


If you have A - B (1 to *) then a collections of B stored in A encodes that info completely. Storing the B in A just duplicates that info, so it's redundant. You can find the same info by searching the As. But normally it's a lot easier to hold that redundant info, so that's what people normally do.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.