The insistence of software architects to eradicate getters originates from seeing programs that are written in Object oreinted projects but still placing all data inside the object and simply using get() to get the data and them make a decision instead of embedding the decision(behaviour) with the data(inside the class) so that the data and behaviour are related. This was the quintessential data-behaviour principle of OO programming not much followed due to the procedural programming hangover that still remains in the industry today.
Accoding to Martin Fowler, example of procedural hangover where getter is only used for data
skMonitor am = new AskMonitor("Time Vortex Hocus", 2, alarm); am.setValue(3); if (am.getValue() > am.getLimit()) am.getAlarm().warn(am.getName() + " too high");
This can be written by coupling data and behavious as follows
class TellMonitor... public void setValue(int arg) { value = arg; if (value > limit) alarm.warn(name + " too high"); } Which would be used like this TellMonitor tm = new TellMonitor("Time Vortex Hocus", 2, alarm); tm.setValue(3);
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.