An object should coherent and loosely coupled


An object can be described in terms of roles, responsibilities, and collaborators.

An object is an implementation of one or more roles; a role is a set of related responsibilities; and a responsibility is an obligation to perform a task or know information. A collaboration is an interaction of objects or roles (or both).
Screen-Shot-2018-04-26-at-17.58.03


Tell, Don't Ask (Law of Demeter)

((EditSaveCustomizer) master.getModelisable()
  .getDockablePanel()
    .getCustomizer())
      .getSaveItem().setEnabled(Boolean.FALSE.booleanValue());

to be

master.allowSavingOfCustomisations();
But sometimes ask
public class Train {
  private final List<Carriage> carriages [...]
  private int percentReservedBarrier = 70;
  public void reserveSeats(ReservationRequest request) {
    for (Carriage carriage : carriages) {
      if (carriage.getSeats().getPercentReserved() < percentReservedBarrier) {
        request.reserveSeatsIn(carriage);
        return;
      }
    }
    request.cannotFindSeats(); }
}

should be converted to

public void reserveSeats(ReservationRequest request) {
  for (Carriage carriage : carriages) {
    if (carriage.hasSeatsAvailableWithin(percentReservedBarrier)) {
      request.reserveSeatsIn(carriage);
      return;
    }
  }
  request.cannotFindSeats();
}

References:

  • Addison Wesley, Growing Object Oriented Software, Guided by Tests

Image cover source: https://unsplash.com/photos/xNKy-Cu20d4