I have a particular problem and I can't seem to get out of it.
I have exploited the BCE pattern and in the entities I have the mother class Contact and the child class ContactCompany and ContactPrivate. The parent class (Contact) implements the method
public abstract void print();
while the ContactCompany class implements:
public void print() {
System.out.format("Company Contacts: %s, name: %s, surname: %s", this.getName(), this.getSurname(), this.getEmail());
}
ContactPrivate class implements:
public void print() {
System.out.format("Private Contact: %s, name: %s", this.name(), this.birthday());
}
In the control I have the following method which prints contacts:
public void printContacts(boolean numbered) {
System.out.println("List:");
Contact[] contactList = getContactList();
for (int i = 0; i < contactList.length; i++) {
System.out.print(""
+ "
");
if (numbered) {
System.out.format("%d) ", i);
}
contactList[i].print();
}
System.out.flush();
}
In the boundary I simply call the method from the control and send it to print.
The mistake is that I can't have prints method in the entity, because the pattern doesn't allow it. How can I solve? How can I print everything without putting the print in the entities?
Thank you!
Alberto
question from:
https://stackoverflow.com/questions/65939527/pattern-boundary-control-entity-in-java 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…