mercredi 9 septembre 2015

interface method that does not make sense for all implementing classes

So I work in this nice project that uses Spring and injects interfaces everywhere. The problem is: in one of my implementers, I have this method that just make sense in that specific implementation. How should I implement this method in the other classes? Ex:

 public interface A {
           public String methodThatMakesSenseOnlyToImplementationA();
       }

Now the implementing classes:

 public class ImplementingInterfaceA implements A {
            public String methodThatMakesSenseOnlyToImplementationA() {
                 //many many crazy things here
            }
 }

For this class, I have to implement the method, but returning empty String looks dirty.

public class Nothing implements A {
        public String methodThatMakesSenseOnlyToImplementationA() {
             // this implementation will never use the method methodThatMakesSenseOnlyToImplementationA
        }
    }

How to solve this issue in a nice way?

Aucun commentaire:

Enregistrer un commentaire