Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interfaces and Versioning

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?

like image 917
Jedi Master Spooky Avatar asked Sep 05 '08 02:09

Jedi Master Spooky


People also ask

Why use interface?

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.

What is the purpose of an interface in java?

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.


1 Answers

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.

alt text

like image 67
rp. Avatar answered Jan 01 '23 23:01

rp.