Replace Primitive with Object


Identify a field or variable that has a primitive type, which you would like to replace with an object of a more meaningful class.


Apply Encapsulate Variable on the field or variable (if it isn’t already encapsulated). This will minimize the number of places that will break when you cut over from the primitive type to the new type.


At this point you’ve succeeded in you original aim - the primitive type is internally stored as an object with a meaningful class instead. You probably have more work to do though.


Follow up

Prompted by Code Smells

Relevant Learning Hours


Back to All Refactorings