Rip's Domain

The war on beans

Posted in ColdFusion, oo by rip747 on April 2, 2008

I’m declaring war on beans. I can’t for the life of me see why they are used and I want someone out there to give me an intelligent answer as to why you should even bother using them.

Here’s my argue for getting rid of them.

For some odd reason, some bright boy a long time ago though that we should break apart the DAL (data access layer) of our application into 3 classes for each table in our database. You had a bean (which had getters and setters), the dao (data access object which contained the CRUD methods) and a gateway (which I was told was for general queries against the table).

Now using this approach, you would load your daos and gateways into the applications scope so that they persisted and were only called once. Then you would use your beans to populate the data you wanted to pass to the dao or gateway and then pass the bean to the dao or gateway.

I find this stupid.

For one it sucks because if you need to make any changed to your dao or gateway, you have to reload your application in order for the changed to take affect. This really can become a nightmare during production as it lock the application scope until all the changed are loaded.

The other point is that now every time I create a new dao or gateway I have to remember to write some code to load it into the application scope. I’m a forgetful person and I can see this causing a problem.

Then there are those that claim that using an approach like this can give your app a performance increase since you’re not constantly creating and destroying objects all over the place. Personally, this is a lie told to us to sell us on the idea. I have never seen a performance increase in an application using this approach and isn’t creating a bean still creating an object?
My whole argument calling for the end of the bean is the plain fact that they are useless when you use an approach like the one table per class design.

When using the one table per class design, you have your getters, setters, CRUD, validation and queries all in one class. By following this design you instantiate the class each time you want to use it, inject the values into the setters and perform the action you want on the class. To me this makes developing and maintaining an application much easier.

For one I don’t have to load a ton of crap into the application scope. Second, now if I need to make a change to a method I don’t have to reload the application and cause a stand still in my application until the action completes. Third, it just makes sense.

I never understood why people would want to create a bean and throw a bunch of values in there and then have to call a whole other class to perform the validation and action. Sure you can put the validation method inside the bean, but that’s not really the purpose of a bean.

So I ask the world…. Why do people even use these things and do they really make an application more maintainable? Personally editing, seeing and tracking the logic in one file is a lot easier then doing it across three files.

Don’t even get me started on TOs.


Leave a Reply

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

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

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

Facebook photo

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


Connecting to %s

%d bloggers like this: