By Peter Bell

Distinguishing attributes from properties

I make a semantic distinction within my beans between the stuff you put into them and the stuff you can get out of them. I happen to use the words attributes and properties respectively to distinguish them. More important than the names are the concepts and the implications for being able to generate richer applications (getting back to application generation again!).

In the applications I generate, object properties often have a 1:1 correspondence to columns (that is not quite true as I generate my DAOs to support aliases and aggregates, but that will be a topic for a whole other post!). Lets take a very simple case where we have a user object that maps exactly to a user table, and let's pretend for now we don't need any related objects (addresses or subordinates), aggregate data (comma delimited list of roles, total salary for the user this year, number of vacation days taken, etc.), or aliases (lets pretend the column names in the db are fine for use within the application so we don't need to alias USR_TBL_FLD17_STR35 or something equally horrific to FirstName - it's already called FirstName in the DB) . . .

So, when we load up our iterating user object, the recordset will have a set of column names like FirstName, LastName and DateofBirth. I call those the object properties, and they are distinguished by the fact that in most simple use cases, properties are settable (it is possible to persist changes to them).

However, for a given use case, I may want to expose getters for FullName, FirstName, LastName and Age (but lets say, NOT date of birth). I call those the attributes of the object and they are typically gettable, but not necessarily settable - try asking a user to enter their age and then saving that in a useful manner that would give you their correct date of birth!!!

By making this distinction and requiring metadata for both object properties and object attributes it allows me to generate much richer applications with much more business functionality without having to break out a code editor and actually work for a living! Please keep this concept in mind as we're going to be building on it in future posts.

Comments
BlogCFC was created by Raymond Camden. This blog is running version 5.005.