| Summary: | Encapsulate Field Refactoring encapsulates a private field | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Melina Mongiovi <melmongiovi> |
| Component: | UI | Assignee: | JDT-UI-Inbox <jdt-ui-inbox> |
| Status: | CLOSED INVALID | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | noopur_gupta, stephan.herrmann |
| Version: | 4.3 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Mac OS X | ||
| Whiteboard: | |||
Please report Java refactoring related bugs to JDT product. According to my experience that book is 16 years out-of-date and I can encapsulate private fields perfectly fine whenever I want as long as I remember to select "Field access in declaring type: use getter and setter". Having to do it without the aid of a tool would be inconvenient. (In reply to Timo Kinnunen from comment #2) > According to my experience that book is 16 years out-of-date and I can > encapsulate private fields perfectly fine whenever I want as long as I > remember to select "Field access in declaring type: use getter and setter". > Having to do it without the aid of a tool would be inconvenient. +1. (In reply to Timo Kinnunen from comment #2) > According to my experience that book is 16 years out-of-date and I can > encapsulate private fields perfectly fine whenever I want as long as I > remember to select "Field access in declaring type: use getter and setter". > Having to do it without the aid of a tool would be inconvenient. Encapsulate Field (http://www.refactoring.com/catalog/encapsulateField.html) and Self Encapsulate Field (http://www.refactoring.com/catalog/selfEncapsulateField.html) are different kinds of refactorings. Encapsulate Field is applied when there is a public field. Self Encapsulate Field is applied in a private field. I think it may confuse the user. In this case, the refactoring applied was Self Encapsulate Field. I would suggest to report a warning message to the user. |
According to Fowler [1] definition about the Encapsulate Field Refactoring, we can only encapsulate public fields. So, this transformation should not be allowed by the tool. Before Refactoring: class A { private int f = 10; } After Refactoring: class A { private int f = 10; public void setF(int f) { this.f = f; } public int getF() { return f; } } [1] Martin Fowler. Refactoring: improving the design of existing code. Addison-Wesley Longman Publishing Company, Inc., Boston, MA, USA, 1999.