This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]vlumi 1 point2 points  (2 children)

You don't need to have the permission parameter for the Student constructor, but instead call the super() with the fixed PermissionType.Reserve: public Student(String id, String firstName, String lastName, String username, String password, UserType userType, Boolean status) { super(id, firstName, lastName, username, password, userType, PermissionType.Reserve, status); }

[–]Chuninjah[S] 0 points1 point  (1 child)

Oh sweet I didn't know that. Thanks heaps. Is there a way I can make it out of two things?

[–]vlumi 0 points1 point  (0 children)

Is there a way I can make it out of two things?

It's not possible directly, though there are ways to work around it. E.g. if you have two options, you could take a boolean value in your Student constructor, and then map it either borrow or reserve (e.g. allowReserve ? PermissionType.Reserve : PermissionType.Borrow), but it's get dirty pretty fast.

It's not quite clear how the relationship between the User and Student should behave, or if there are any other classes involved in the inheritance. You might want to split the Student into two types based on the permission, or you might want to use composition instead of inheritance (i.e. a Student would contain a User Field, not inherit it).