Before Refactoring
class Employee{ String phoneNumber; someMethod1(){ String area = phoneNumber.subString(...); } } class Employer{ String phoneNumber; someMethod2(){ String area = phoneNumber.subString(...); } }
After refactoring
class Employee{ Phone phoneNumber; someMethod1(){ String area = phoneNumber.extractAreaCode(); } } class Employer{ Phone phoneNumber; someMethod2(){ String area = phoneNumber.extractAreaCode(); } } class Phone{ String number; String extractAreaCode(){ ... } }