Search code examples
javapolymorphismumlfactoryclass-diagram

Polymorphic Array class Rules (Supermarket program)


So I have a class called UserList which contains an attribute called Users which is an ArrayList of my abstract class User.

enter image description here

My User Class has subclasses Customer and Owner.

enter image description here

enter image description here

Within the UserList I create new types of user based on my file which I load inside the UserList class.

enter image description here

When the File loads in I have method inside UserList that creates an Owner. It checks if there is 1 owner inside the file. If there is no Owner or more than one owner it throws an error.

Does it make sense to have a UserList class or rather a CustomerList class and an Owner class (given that my UserList class would connect my supermarket program)?

If these rules apply can I have methods in my UserList class that verifies the type of user (Customer,Owner) like boolean IsOwner(User CurrentUser) and boolean IsCustomer(User CurrentUser)?

Also considering that my program will be able to implement Employees in the future I feel like the UserList class makes a bit more sense.


Solution

  • UserList, CustomerList, SoleOwnerList, EmployeeList all make sense depending on your intent.

    If your intent is to manage a list of users, just go for the UserList ! Generalization is meant to be able to cope with such case were users are something more general to mean different categories of users.

    But I tell you something that you already know:

    Also considering that my program will be able to implement Employees in the future I feel like the UserList class makes a bit more sense.