You will need a List<Person> . Your diagram offers inheritance, so you want to have a superclass collection and let polymorphism do the rest.
Your code can do this:
List<Person> people = new ArrayList<Person>(); // Any class that extends person can be added people.add(new Customer()); people.add(new FieldEngineer()); for (Person person : people) { System.out.println(person); }
Your design, expressed, will not allow engineers to be Customers or sales engineers to enter the field, but it is a curse of inheritance in cases like yours.
A better design, if you need flexibility, might be to keep the Person class and assign the Person role in the style of the decorator.
The decorator will add behavior using composition rather than inheritance, for example:
public class Customer { private Person person; public Customer(Person p) { this.person = p; } public void buyIt() {
source share