Community
Participate
Working Groups
I20070502-0010 Given: package test; public class UFO { private int x; private int y; private int z; private String homePlanet; public UFO(int x, int y, int z, String homePlanet) { this.x= x; this.y= y; this.z= z; this.homePlanet= homePlanet; } public String toString() { return "An UFO from " + homePlanet + "is at position " + "[" + x + ", " + y + ", " + z + "]"; } } It is possible to introduce a parameter object 'Position' for the constructor 'UFO', but this is not possible for the fields. The refactoring invoked on class 'UFO' and generating a field encapsulation object called 'Position' for fields x/y/z should produce a result like: package test; public class UFO { private static class Position { private int x; private int y; private int z; } private Position position; private String homePlanet; public UFO(int x, int y, int z, String homePlanet) { position= new Position(); position.x= x; position.y= y; position.z= z; this.homePlanet= homePlanet; } public String toString() { return "An UFO from " + homePlanet + "is at position " + "[" + position.x + ", " + position.y + ", " + position.z + "]"; } } Of course with options to generate getters/setters and all the like. Even more interesting in combination with introduce parameter object.
see http://www.refactoring.com/catalog/extractClass.html
Created attachment 74258 [details] Initial Release First proposal for this refactoring. The javadoc is not quite ready, and the ui is more a stub. But one might test the results.
Personally I am not so happy about 'Extract Class' as name for this refactoring. Before releasing anything to CVS I would like to have the final name for it. My suggestion would be 'Introduce Field Object'. This shows the similarity to 'Introduce Parameter Object' and is not so close to the other Extract Interface, Extract Super Class and the like. The Extract* refactorings are mostly side-effect free, but Extract Class can not be completely without side-effects.
We should use the name that is used in the refactoring references as in Fowlers book. The refactoring is called 'Extract class' everywhere. 'Introduce Field Object' is not in use. 'Extract class from fields' and 'Extract class from parameters' would be a possibility.
Created attachment 74534 [details] Close to final Descriptor javadoc is still incomplete Menuitem at wrong position, missing in context menu
patch released > 20070725 Can you have a look at the following issues: - Javadoc in descriptor - using progress monitor in ExtractClassRefactoring - make sure all tests pass
Created attachment 74567 [details] Updated Patch Fixed the tests that were broken by the patch tool Finalised doc in ExtractClassDescriptor Moved getAssignedValue() to GetterSetterUtil
patch released > 20070725
This refactoring will be available in 3.3M1+
Verified in I20070809-0010.