Hi everyone, I'm new to design patterns and currently trying to create a simple example of the following actor-role pattern (sometimes known as player-role pattern):
player-role.jpg
I have no problems creating the classes and inheritance relationships. My confusion is, let's say I want to create a new Student object who has the role of undergraduate. When I construct the Student object, how/where do I pass the information that I want the Student to be a postgraduate? Let's say this is my Student class:
public class Student { private String name; private String degree; private String studentId; private LevelRole level; private boolean hasPaidFees; public Student(String name, String degree, String studentId, boolean hasPaidFees) { this.name = name; this.degree = degree; this.studentId = studentId; this.hasPaidFees = hasPaidFees; }
and let's say my UnderGraduate class is this:
public class UndergraduateStudent extends LevelRole { private String description; private Student student; public UndergraduateStudent(String description, Student student) { this.description = description; this.student = student;
If I construct a new Student object, I don't understand how to set the level role as undergraduate:
Student s15764 = new Student("Simon Burns", "MSc Physics", "15764", true);
I'm not sure if it's too much to ask, but if anyone could show me the Java code of the above Student/level role/attendance role example, I'd be so grateful. I've genuinely searched hard for a simple Java actor-role example and I'm surprised very little has come back (I can find good Java examples for just about every other single design pattern, but this one is elusive).
Many thanks, I really appreciate your time.