views:

222

answers:

5

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?

+2  A: 

The purpose of an interface is to define an abstract pattern that at type must implement.

It would be better implement as:

public interface ISomething

public class Something1 : ISomething
public class Something2 : ISomething

You do not gain anything in the form of code reusability or scalable design by creating multiple versions of the same interface.

FlySwat
+2  A: 

I don't know why people downvote your post. I think that good naming guidelines are very important.

If you need to maintain compatibility with prev. version of the same interface consider using inheritance. If you need to introduce new version of interface consider following rule:

Try to add meaningful suffix to you interface. If it's not possible to create concise name, consider adding version number.

aku
+5  A: 

Ideally, you shouldn't be changing your interfaces very often (if at all). If you do need to change an interface, you should reconsider its purpose and see if the original name still applies to it.

If you still feel that the interfaces will change, and the interfaces changes are small (adding items) and you have control of the whole code base, then you should just modify the interface and fix all the compilation errors.

If your change is a change in how the interface is to be used, then you need to create a separate interface (most likely with a different name) to support that alternative usage pattern.

Even if you end up creating ISomething, ISomething2 and ISomething3, the consumers of your interfaces will have a hard time figuring out what the differences are between the interfaces. When should they use ISomething2 and when should they use ISomething3? Then you have to go about the process of obsoleting ISomething and ISomething2.

Garo Yeriazarian
+4  A: 

I agree with Garo Yeriazarian, changing interface is a serious decision. Also, if you want to promote usage of new version of interface you should mark old version as obsolete. In .NET you can add ObsoleteAttribute.

aku
+3  A: 
rp