Preserve both ends during a transfer

A staffing model permits an employee to belong to zero or one department and each department to contain zero to four employees. Java stores both an employee's department reference and each department's employee collection. They must agree after every public method returns or throws an exception.


All relationship fields are private, and transfers use this public operation:


Java
public void transferTo(Department next) {
    if (department != null) {
        department.removeInternal(this);
    }
    department = next;
    if (next != null) {
        next.addInternal(this);
    }
}


addInternal throws before changing its collection if the destination is full. Assume execution uses one thread. Internal removal and insertion can be made non-throwing once their conditions have been checked. A rejected transfer must preserve the original links.


Which replacement strategy also handles transferring an employee to their current department and transferring to null?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Implementing Class Diagrams in Java Questions: