Generating Interface from a Class

4 January 2008

Some times you have a class with concrete methods and you want to declare an interface with all the methods in the class. You may call it backtracking. In this post, I will write about how to do this in Eclipse.

Suppose we have a class called Students that has methods defined in it. We want to generate the interface for it in Eclipse. Simply right click the class name, or simply right click anywhere in the code and select Refactor > Extract interface. A new window will open. Name the interface and select the methods you want to put into the interface. All the methods in the Students class will be listed in the window and by default none will be selected. After naming and selecting the methods, you can get the preview as well or simply click ok to generate the interface.

Generating Interface

The signature of Student class will also change to:

public class Students implements StInterface  {}

This approach is a backtracking approach and generates the interface in no time. Try it.

del.icio.us:Generating Interface from a Class  digg:Generating Interface from a Class  spurl:Generating Interface from a Class  wists:Generating Interface from a Class  simpy:Generating Interface from a Class  newsvine:Generating Interface from a Class  blinklist:Generating Interface from a Class  furl:Generating Interface from a Class  reddit:Generating Interface from a Class  fark:Generating Interface from a Class  blogmarks:Generating Interface from a Class  Y!:Generating Interface from a Class  smarking:Generating Interface from a Class  magnolia:Generating Interface from a Class  segnalo:Generating Interface from a Class  gifttagging:Generating Interface from a Class

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: Generating Interface from a Class

Leave a Reply