Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Design pattern: actor-role

  1. #1
    Junior Member
    Join Date
    Nov 2017
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Design pattern: actor-role

    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.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Design pattern: actor-role

    Also posted here: https://coderanch.com/t/695312/java/...ern-actor-role
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Flyweight Design Pattern
    By novicenovice in forum Java Theory & Questions
    Replies: 4
    Last Post: September 19th, 2013, 12:20 PM
  2. Design Pattern for Online booking
    By tcstcs in forum Java Theory & Questions
    Replies: 0
    Last Post: January 14th, 2013, 05:21 AM
  3. decorator design pattern
    By chalapathi in forum Java Theory & Questions
    Replies: 2
    Last Post: May 8th, 2012, 03:39 PM
  4. What is difference between Design Pattern and FrameWork ?
    By casperl90 in forum Web Frameworks
    Replies: 2
    Last Post: August 8th, 2011, 03:17 AM
  5. Optimizing Singleton Design Pattern
    By tcstcs in forum Java Theory & Questions
    Replies: 4
    Last Post: April 19th, 2011, 02:13 AM

Tags for this Thread