Replace Primitive with Object

Examine

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

Prepare

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.

Implement

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.

Clear

Follow up

Prompted by Code Smells

Relevant Learning Hours

Sources

Back to All Refactorings