Finding superfluous interfaces?

I am working on a large, existing code base that has lots of interfaces and deep interface hierarchies.

Can IDEA help me finding interfaces that are superfluous in the sense that they are actually implemented and their methods are actually called, but the methods are always called on concrete classes?
For example in my point of view HasCost in this (very much contrived) example is superfluous:

    interface HasCost {
        long getCost();
    }
    
    interface HasName {
        String getName();
    }
    
    class Article implements HasCost, HasName {
        public long getCost() { return 0; }
        public String getName() { return ""; }
    }
    
    class Client {
        void printName(HasName hasName) {
            System.out.println(hasName.getName());
        }
    
        void handleArticle(Article foo) {
            System.out.println(foo.getCost());
        }
    }


In this example I could remove HasCost (together with the corresponding "implements" and possibly @Overrides) without changing semantics.


Finally:
Do you agree that it is a Bad Thing to require implementing interfaces to try and enforce similarity when there is no real functional domain meaning to the interface (exemplified by how nonsensical it is to say "Article is-a HasCost").
Any supporting documents for that?

Please sign in to leave a comment.