Friday, April 13, 2007

Why ActionForm is not an interface?

There are few reasons why Action Form is not an interface.

Adding a new method in interface (in next version of struts) will break earlier application's form bean. While in case of base class one can add new method as default implementation which doesn't break earlier applications to use new version.

If Action Form is an interface, people using struts would be tempted to use their business objects as Action Forms which can cause following problems.

Action Form is implemented to accept any value from HTML form and then validate those properties, If any of them are found to be incorrect; can be corrected on the fly. While business objects are not designed to buffer invalid data so programmer cannot change incorrect values on the fly instead they will get an exception.

Some business objects are designed to start transactions, lock resources like database while they are used. In that case; even if input fields from HTML form are invalid, resources will be locked and transactions will start which is illegal usage of resources.

Auto population mechanism of struts is designed to populate object first and then validate. In that case if business objects are used as Action Form and a property of a business object is meant to change system state, Invalid value may affect system and application in turn. So using one layer of ActionForm will block such invalid property values.

Labels: , , ,


Post a Comment

Subscribe to Post Comments [Atom]

<< Home