Hi-Lighter Hi-Lighter - 2 months ago 32
Java Question

How do I implement an "include" in Java Class Association

I understand what inherit does in Java Class Associations which is the extend feature. But I don't know what include means, I've researched and can only find implements but not sure if that's what includes means.

Here is the UML design.

StudentRecord (1) ---- includes ---- (1) Student
FullTimeStudent (1) ---- inherits ----> (1) Student


Here is the difference, technically:

First one: StudentRecord (1) ---- includes ---- (1) Student This means StudentRecord contains a member variable of type Student, something like

public class StudentRecord {
    private Student student;
    // and other member variables and functions

Second: FullTimeStudent (1) ---- inherits ----> (1) Student This means that FullTimeStudent is a Student. like:

public class FullTimeStudent extends Student {
    // override stuff, add new members

See the difference? One says "contains", while the other "is a". i.e. you can write something like:

Student s = new FullTimeStudent();


StudentRecord sr = new StudentRecord(student);
// given you have such a constructor, or: