ConstructiCat Logo
CodeBust.
Browse section ▾

Alternative Classes with Different Interfaces.

Two classes perform identical functions but have different method names.

##Signs and Symptoms

Two classes perform identical functions but have different method names.

class SmtpMailer {
  private final SmtpTransport transport = new SmtpTransport();
  void send(Message msg) { transport.write(msg); }
}
class EmailSender {
  private final SmtpTransport transport = new SmtpTransport();
  void deliver(Message msg) { transport.write(msg); }
}

##Reasons for the Problem

The programmer who created one of the classes probably didn’t know that a functionally equivalent class already existed.

##Treatment

##Payoff

  • You get rid of unnecessary duplicated code, making the resulting code less bulky.

  • Code becomes more readable and understandable (you no longer have to guess the reason for creation of a second class performing the exact same functions as the first one).