Full agreement with general idea. But given example that should fix supposed duplication is a regression from readability perspective. TextReplacer()->replace() API is awful. First it's more code not less and most important it's way harder to understand. I would classify this as clever code or overengineering. Refactoring like this make sense when repeated code have more logic, some local variables, in general you have to spend time to understand what it's doing. In this case abstracting and giving method descriptive name make total sense. In your example it's making simple code complicated.
I agree with you. It is an over engineer example.
I tried to find a better one and also shorter.
Many examples i find in real world are too long to embed.
BarTech
developer
Full agreement with general idea. But given example that should fix supposed duplication is a regression from readability perspective.
TextReplacer()->replace()API is awful. First it's more code not less and most important it's way harder to understand. I would classify this as clever code or overengineering. Refactoring like this make sense when repeated code have more logic, some local variables, in general you have to spend time to understand what it's doing. In this case abstracting and giving method descriptive name make total sense. In your example it's making simple code complicated.