In a coding exercise I want to create a Java software for an hypothetical shop: I have a User superclass and three subclasses: administrator (who can manage the product catalog and the customer’s list), customer (who chooses the products from the catalog and the system creates a list to be shown to an employee in order to proceed with the payment) and employee (who helps the customer with the payment and, if there are no problems, finally sends an email to the customer). Obviously these are functions that I just invented to justify the presence of three different User types.
User has the attributes: id, email, password. The administrator attributes are: first name, last name, salary, phone number. The kitchen attributes are: number of employees, monthly running expense. The customer attributes are: first name, last name, date of birth, profession, residence.
Somewhere in the software code I obviously need to create new instances for each type of user.
Why and how should I use a creational pattern (abstract factory / factory method) instead of the parameterized constructors of the three subclasses?
Alex Boccadamo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.