
One of the step in test driven development is "refactoring your code".
One of the main step of refactoring is the act of removing duplication.
You can read from wikipedia: "The concept of removing duplication is an important aspect of any software design".
I think duplication is pretty difficult to identify; there are a LOT of different kind of duplications. Some of them are stated here.
Today i notice another kind of duplication, something i can call like 'subset duplication' where a function does a little less of another bigger function.
For example:
addTicket(id, value) and
addTicket(id, value, comment) and
addTicket(id, value, date)
I think it's better to have only one function without say the same thing in one thousand of little different modalities. I like expose the differences, not hide them.
One solution could be addDefaultTicket() that return a ticket so you can customize with fluent interfaces: addDefaultTicket().withComment("xxx").
I think there are plenty of other solutions, but the point is always the same: trying to find the best and unique solution.
Nessun commento:
Posta un commento