vendredi 29 mai 2015

Why separation of interface and implementation?

In production code I often see classes defined as follows:

public interface SomeComponent { // Some methods }
public class SomeComponentImpl implements SomeComponent { // Some methods}

public interface SomeComponentV2 extends SomeComponent { // Some methods }
public class SomeComponentV2Impl extends SomeComponentImpl implements SomeComponent { // Some methods }

Why in this case we want to separate the interface and its implementation?

Or put it this way, why is it bad to simply have one base class, and let V2 extend/override V1 as follows:

public class SomeComponent { // Some methods }
public class SomeComponentV2 extends SomeComponent 
{
  // Override methods for reimplementation
  // Add new methods for new features.
}

Aucun commentaire:

Enregistrer un commentaire