views:

30

answers:

2

Hi,

how can I add a field, getter and setter to all implementations of MyInterface (in the current project or folder?)

A: 

I don't think there's a one-step way to go about this. You could add the getter & setter to the interface, then let the compiler tell you where your implementers are, and it should be a simple copy & paste to place the field, getter, and setter into every class after the first.

Alternatively, you could transform your interface into an abstract class, or introduce an abstract class between your interface and your concrete classes, but that's only if your classes don't already extend other classes.

Carl Manaster
+1  A: 
  1. Open the source file containing the interface. Select the interface's name and hit F4 (Open type hierarchy).
  2. In the type hierarchy view, select all of the classes that implement your interface. The hierarchy is displayed in a tree-like fashion so selection should be very easy.
  3. Right-click over your selection, select Source, then Override/Implement Methods....

Mission accomplished.

[Edited]

When I wrote these steps, I thought that your intention was to create stubs of newly-introduced interface methods, in all classes that implement that interface.

Now that I am re-reading your request, I'm having a hard time understanding what it is exactly that you want to do. You wrote:

how can I add a field, getter and setter to all implementations of MyInterface

So, you have an interface named MyInterface and 1,000 classes implementing it. You would like to introduce a new field, a getter and a setter for that field. So I guess my (and perhaps others') first difficulty is that you can't add a field to an interface, unless it's final - so your wish to "add a field to an interface" just doesn't sound right.

I suppose it would help if you give us a 30,000ft high-level diagram / explanation about your hierarchy and exactly what it is that you're trying to accomplish.

Isaac
still the field is missing, or do i miss something?
Jan
I'll edit my answer
Isaac