简体   繁体   中英

Can we assign an attribute name for a Class even that attribute is a column in a different table?

Ok, here is my DB

Member Table
memberID- Name -...
1       - Tom
2       - Mary
...

Event table
eventID - address
1       - 122NY...
2       - 23 Cali
...

PaidMember table
orderNumber - eventID - memberID
1           - 1       - 2
1           - 1       - 3
..

Note: each Event can have many members and each members can be in many event. However, only PaidMember is allowed to participate an event.

SO, here is how I design classes:

public class Member{
  private String name;
  private int memberID;
  //all Set and Get methods here
}

public class Event{
  private int eventID;
  private String address;
  //all set and get methods here
}

My question is that, can I put private int orderNumber into Member? but the orderNumber is depended on a particular event

 public class Member{
  private String name;
  private int memberID;
  private int orderNumber;
  //all Set and Get methods here
}

or should I create PaidMember class? I am thinking to do like this but not sure if it is ok

 public class PaidMember{
  private Member member;
  private Event event;
  private int orderNumber;
  //all Set and Get methods here
}

if

each Event can have many members and each members can be in many event. However, only PaidMember is allowed to participate an event.

Then better thing to do is to add an eventList attribute to Member class. this attribute would hold the related events to the Member object. and have an memberList attribute in Event class. that attribute would hold related members to an Event object.

eventList, memberList can be of type List or it may be an array.

PaidMember should be a subclass of Member.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM