Why Should You Use Getters and Setters?

Some people aren’t very fond of accessors and mutators. On the surface they seem like needless functions, a waste of code when a simple class.variable would suffice. Some variables really are better off being set with variable = foo than with a mutator. On the other hand, other data types have such complex initialization procedures it’s easier to pass values into a mutator. C++’s maps are a good example of this kind of situation. Which is easier, std::map.insert(std::pair<Foo, Bar>(var1, var2)); or SetMap(var1, var2);?

Continue reading

Advertisements