Despite not being a big fan of Beans generally, I do find that there are situations in which they are useful. One of those is as configuration objects to pass in to a component. I can add the data in one packaged set.

In reading about Clojure recently, one of the big advantages of Clojure is immutable variables. I wouldn't want immutable variables in ColdFusion all of the time, but it would be really nice sometimes.

So, I made Beany as my Bean implementation and made it to allow for immutable data.

Here is a basic implementation of Beany:

oMyData = new com.sebtools.Beany(FirstName="Benjamin",LastName="Franklin");

Now, I can get the FirstName using




I can change the first name using




If I wanted to make sure that the values on my Bean could no longer be changed, I would call:


If I wanted to implement this Bean as immutable from the outset, I could do the following:

oMyData = new com.sebtools.Beany(mutable=false,FirstName="Benjamin",LastName="Franklin");

I also sometimes extend Beany and put the data directly in the file. I especially like to do this for data that is sensitive. That way, I can .gitignore the file that holds that data and keep it out of the repository.

For example, I have an AWSCredentials.cfc file:

<cfcomponent displayname="AWS Credentials" extends="com.sebtools.Beany" output="no">

   region = "us-east-1",

   SMTP_username = "REDACTED",
   SMTP_password = "REDACTED"


I call the component with this code:

oAWSCredentials = new AWSCredentials();

That allows me to pass that into any component that connects with AWS without having those codes in the repository.

Once Beany is immutable, it will throw an exception any time any code attempts to change a value in Beany.

So, that is the basics of Beany. Beany is part of my free com.sebtools package for ColdFusion. Let me know what you think!

Related Blog Entries

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.