I know autmatic getters and setters are considers bad as they tend to break object’s encapsulation. They also move the work that should have been done within the object outside.
Allen Holub is a big advocate of avoiding them. In one of his presentations he gives this example as bad design:
Here currency conversion happens outside the Money class and is spread across the application wherever conversion is needed.
As a fix he introduces this:
It makes sense to me that a Money object now uses Currency object and Money arithmetics are done within the Money class, but this line m=currency.convertToYourCurrency(m)
I don’t understand.
How will the Currency method public Money convertToYourCurrency(Money money);
know what’s the argument’s currency? Is it going to use a getter? If it delegates to Money for conversion why bother calling it from within Money to begin with?
Did Mr. Holub make a typo on his slide or am I missing something obvious?
Link to the class: https://vimeo.com/user22258446/review/79095046/9c0ffa90c8 this is from ~44:22