You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Curley, John" <Jo...@NielsenMedia.com> on 2003/03/13 22:34:55 UTC

Final Accessor/Mutators in Struts Forms/Action Classes

Hi, All:

Just like to get people's opinion on this small issue.........

Now, I have been told that accessors and mutators should be declared final
(since these methods are not normally intended to be overridden).  By doing
this, you take away the polymorphic nature of the method and allow a Java
compiler to inline the method if the compiler chooses.

Obviously, this would make the code more efficient.  But again, if the
methods are not called that frequently, the code savings are most likely
insignificant.

Now, when viewing the Form beans in Struts I haven't seen this done.

Is there any harm in declaring accessor/mutators this way........

public final int getAssociateTotal()
{
     return associateTotal;
}

public final void setAssociateTotal(int associateTotal)
{
    this.associateTotal = associateTotal;
}

In regular Java classes, I almost always did this.  I wouldn't do this in an
EJB since I know that the App Server will sub class the classes we write
(Remote, Home, Bean) and may want to override these methods.

However, do you think this would be a problem in something Struts related,
such as an Action or Form?

Just a side question that went off in my head.  I understand in the grand
scheme of things, it's probably not a showstopper.  :-)

John

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org