I have to build a library management system and i’ve run into problems while trying to implement user types or profiles. I’ve already got a superclass user and two other subclasses of User, Student and Teacher, each with their own “characteristics”. The thing is i have to implement 7 types of users (5 types of students and 2 types of clerks) based on the number of books they can borrow and the amount of time they can keep the books until they have to return them. Those are the only 2 differences between the classes.
How would you implement this? Inheritance? I’m looking for a clever way to implement this and i would love to hear your thoughts on this.
Thank you very much.
As a good rule of thumb, anywhere you see a noun in a project specification it’s a good candidate for a class. If those nouns have relationships in the project spec, they probably aught to have one in your code too.
All of your people would fit in the category of a
Userso perhaps this should be an interface they would all inherit. Down from this they appear to fit into two categories,StudentandStaffperhaps these should also be abstract classes / interfaces. Then you have your 7 concrete classes. 2 inheritingStaffand 5 inheritingStudent.So you’d end up with something like this..

Of course, this design depends on what every
Usermust do, what everyStaff/Studentmust do but I’ll leave the very specific details to you.