Every now and then, an article pops up that slams the use of Getter() and Setter() methods in object oriented programming (OOP); promptly, those new to OOP, like myself, shiver, wet ourselves, and franticly run around trying to escape the daunting feeling that we have no idea what in the heck we are doing. To me, these articles are never constructive - all they do is tell us that we're wrong using examples that rarely relate to our own experience (at least for me) and offer very few, if any, solutions to our common problems. You might as well tell me that I'm fat and that it's all my fault and then not offer me any dietary advice - it's basically the same thing.
As someone who is very new to OOP and struggling to wrap my head around all the new principles and best practices, I wanted to voice my frustration with such articles not so that people would stop writing them - very much to the contrary; I want to voice my frustration in hope that people will continue to write these articles and to write them much better.
So, here are my frustrations:
First off, let's not use Java-based examples. Obviously, the author can write in whatever language he or she knows. But, if you are a ColdFusion developer, don't just point me to a Java article. While ColdFusion sits on top of Java, these are very different languages and live by very different rules. Yes, I understand that the principles of object oriented programming can be ported from language to language, but remember that people like me are new to this, so help us out by providing a comfortable, familiar environment for learning.
In ColdFusion, there's really no difference between Ints, Doubles, Floats, and Strings (etc.), so simple-data-type encapsulation means nothing to me. Don't talk to me about what happens when a hundred references to an INT suddenly need to be a 100 references to a BIGINT. In a loosely typed language like ColdFusion, this is simply not a concern. Now, if a reference to an INT suddenly needs to be a reference to a Collection of objects, then yeah, we have a problem. Give a solution to gracefully hide that type of change and I can eagerly follow along.
Do people really use Builders in ColdFusion? Do they make sense in a loosely typed language? I have seen several Java examples that use Builders to allow Objects to create a sort of lightweight transfer object for their internal data which is then used to build View output. The explanation of this seems to be that the UI logic is stored in one place and that all the data in the object can be transformed to string data (internally to the object) such that its data type implementation is hidden. But my question is, if simple-data-type issues do not exist, does this sort of solution make sense? Also, is the UI logic really only in once place, or do I have to build a new Builder for every View that uses this sort of data (think single FORM view, single display view, bulk list view, bulk edit view, single delete view, bulk delete view, JSON response, XML response, etc.)? My gut is screaming at the idea of a Builder. Something about it infuriates me - now not only do I have a View, I also have to have a Model object and a Builder to help the two to communicate, not to mention a Controller; one page takes how many objects to work?
Are we going to be creating GOD objects? If we are to avoid passing around data, then doesn't that force our business objects to become huge objects? Knowing how to Validate, Save, Read, Delete, and whatever else needs to be done with the internal object data?
What about the idea of consistent access, even when done internally to an object? For example, I see objects all the time that have many calls to getDSN() rather than referring to the DSN value directly so that access logic to that variable is not duplicated. Are we supposed to get rid of all internal Get() methods as well and duplicate that type logic throughout the object?
So anyway, I am not trying to say that Getters() and Setters() are good or bad - I, quite frankly, don't understand OOP thoroughly enough to have an opinion. All I am asking for is that the articles that get written on the topic have better, more relevant examples.