Can't add a method to a class you don't own? Use a Foreign Method!
- Create the method in YOUR code
- Pass the utility object as parameter
Example (JS): function formatWithTimezone(date) {
return StringUtils.format(date) + " UTC";
}
#ProgrammingTips#CodeRefactoring
Remove Middle Man:
When a class just delegates calls (adding no value):
- Delete the delegating methods
- Make clients call directly
Before:
manager.getEmployee().getName()
After:
employee.getName()
Cut the pointless proxy!
#CleanCode#Refactoring