OOP – Generic Setters and Getters

When writing a CFC that models an object of a domain, you can have a bunch of properties and then a bunch of setter’s and getter’s methods, a couple for each property.  Basically each setter sets a property with a value passed as argument, and each getter retrivies the value of a property .


Instead of writing a setter/ getter couple for each property, we can surely write abstract methods adding an argument to each method to specify the property we will set or retreive.


Now that you have defined generic methods, the next step is to write a base class containg the abstract methods just defined, and write concrete classes that extend the base one,  in which you’ll define only properties. Other than generic setter and getter, the base class has methods to verify if a property is settable and/or gettable, if a value passed to set a property is of the same type of the property ecc. To do so, you use <cfproperty> tag’s standard and custom attributes.

I ‘ve used this method for a long time. You can download code and samples.

Lascia un Commento

Fill in your details below or click an icon to log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Log Out / Modifica )

Foto Twitter

You are commenting using your Twitter account. Log Out / Modifica )

Foto di Facebook

You are commenting using your Facebook account. Log Out / Modifica )

Connecting to %s

Follow

Get every new post delivered to your Inbox.