I am designing a new System and I have a lot of Interfaces that will grow over time with the system. What is the best practice to name this interfaces
ISomethingV01
ISomethingV02
etc
and I do this
public interface ISomething{
void method();
}
then I have to add method 2 so now what I do?
public interface ISomethingV2:ISomething{
void method2();
}
or same other way?
Why do we use an Interface? It is used to achieve total abstraction. Since java does not support multiple inheritances in the case of class, by using an interface it can achieve multiple inheritances. It is also used to achieve loose coupling.
In Java, an interface specifies the behavior of a class by providing an abstract type. As one of Java's core concepts, abstraction, polymorphism, and multiple inheritance are supported through this technology. Interfaces are used in Java to achieve abstraction.
I think you're overrusing interfaces.
Meyer and Martin told us: "Open for extension but closed for modification!"
and then Cwalina (et al) reiterated:
From Framework Design Guidelines...
In general, classes are the preferred construct for exposing abstractions. The main drawback of interfaces is that they are much less flexible than classes when it comes to allowing for evolution of APIs. Once you ship an interface, the set of its members is fixed forever. Any additions to the interface would break existing types implementing the interface.
A class offers much more flexibility. You can add members to classes that have already shipped. As long as the method is not abstract (i.e., as long as you provide a default implementation of the method), any existing derived classes continue to function unchanged.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With