3 ms·
The only cost of duplication is when you're making changes to it. Let's say that the cost of typing, checking and finding the code to change is "t". Duplication
by fendy3002 7y ago
The only cost of duplication is when you're making changes to it. Let's say that the cost of typing, checking and finding the code to change is "t". Duplication makes it "n*t". Abstraction, in case of no special case, makes it "1t".
So if "n" is somehow big, it'll be costly to make changes and abstraction makes sense.
However do not abstract similar code for different behavior early (as in OP's case), but abstract similar behavior early (ex: file system, db access)