Change Unidirectional Association to Bidirectional

You have two classes that need to use each other's features, but there is only a one-way link.

Add back pointers, and change modifiers to update both sets.

For more information see page 197 of Refactoring

Additional Comments

Doing a remove

In the example I showed an addOrder method, but I didn't show the removeOrder method. If you want to do a remove, you would write it like the add method but set the customer to null.

Class Customer ...
 void removeOrder( Order arg ) {
  arg.setCustomer( null );
}

Contributors

| Refactoring Home | | Alphabetical List |