How to change an interface in Java and its consequences?

What is the best practice for changing an interface in an application. If the interface has been implemented by many Java classes, what would be the best way to change it? Are you going to extend to a new class? Are you going to use any design pattern? or do you use delegation (I don't think there is any way using delegation)? Are you going to use deprecated annotation at all?

is this the best solution?

public interface interface1

public interface interface2 extends interface1
public void newMethod()


There are two ways that immediately spring to mind.

  1. In your IDE, use a refactoring tool to change the interface. The more advanced IDE's (Eclipse can - I don't know about others) can refactor any known implementations immediately. This requires the affected projects to be open.
  2. Your solution, MyInterface2 extends MyInterface is used extensively too, because it doesn't break existing implementors.

If your solution came up in a code audit or review, I wouldn't reject it - it's fine, IMHO.

If you own the code, the best way to change an interface is to fix all references to it - rather than leave deprecated code around.

If this method is not needed by all other classes implemented interface1, then I think by doing this you can avoid major code changes.

Then, next question, do we need this in interface2 (or) just having in the required class is enough?

If you don't want to define this new method as contract, in other words no other classes need to implement, then I wouldn't even create a interface2.

You can use design patterns. Abstract Factory or Bridge pattern can be used

Need Your Help

Getting data of a particular row in a table view controller corresponding to the click of a button

iphone objective-c

I am new to IOS development. I am working on an app in which I have few rows and a button in front of each row. In the cellForRowAtIndexPath I have created a function called buttonPressed() and in ...

Time based sprite movement when coming back from background

objective-c sprite-kit

I'm pretty new working with SpriteKit. I have a working example of an game I want to develop. I have some time based movements of sprites, with these I mean:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.