Quantcast
Channel: JetBrains Developer Community : Thread List - IntelliJ IDEA Users
Viewing all articles
Browse latest Browse all 5661

Finding superfluous interfaces?

$
0
0

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?


Viewing all articles
Browse latest Browse all 5661

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>