I am new to java and programming overall, today I encountered a problem with these 3 relations. Unfortunately from my materials I can't understand how to implement them. I hope somebody can make this clear for me.
1) Association For example I have 2 classes. Student and School, this is association with multiplicity 1:1, I understand that in each class, I'll have atribute that refers to the other class. But my question is, if In constructor do I declare these reference variable? Do I also create set and get methods for them? What if that association is with multiplicity 1:N ? I have reference variable, that refers to list, do i declare that somehow in constructor too? Do i create set and get methods for that array list?
2) Aggregation From what I understand, in terms of implementation in Java aggregation is nothing but one-way association. So the reference variable is only in one class. Is my hypothesis true?
3) Composition I know that composition is special type of aggregation. So what I think, in terms of implementation in Java, that it'll be one way association too, so the implementation will be same and the only thing that differs is how we recognize this relation outside of programming.
If anybody could help me I would really appreciate it
Sorry that I didn't show any example, true is that It would help me to describe my thoughts.
Lets say we have class, student
public class Student {
private String name;
private School school;
}
public Student(String namei, School school) {
this.name = name;
this.school = school;
}
If class school, would have an atribute private Student student, it would be an association. But if not, and the only reference atribute would be in class Student, Am I right if I would say that the relation between those classes is Aggregation ?
What if we change it up a little bit and we say, that school, needs to have students. So the only thing we change would be the context, how we think about the subject and nothing else, if we would do that, Would I be right if I would say that the relation would be Composition?