Re: "protected" attributes in Component .java files.

From: Chuck Hill (chil..lobal-village.net)
Date: Tue Jul 03 2007 - 01:25:05 EDT

  • Next message: Ulrich Köster: "Re: Apple WebObjects issue with JApplication plugin 2.0.6"

    On Jul 2, 2007, at 2:44 PM, Janine Sisk wrote:

    > On Jul 2, 2007, at 2:35 PM, David Avendasora wrote:
    >
    >> The problem I'm running into is that almost all the attributes that
    >> were setup in WOBuilder are "protected", and now Eclipse is reporting
    >> that the attributes don't exist. If I mark them as "public" then the
    >> problem goes away.
    >>
    >> What is the proper way to handle this?
    >
    > I'm feeling an urge to channel Chuck....
    >
    > He has taught me, forcefully :)

    Who? Me?

    > that the right thing to do is to leave these protected and write
    > getter and setter methods for them.

    Sigh. Well. Not forcefully enough apparently. :-P Make them
    private and write getter and setter methods for them. Code to the
    API, not the implementation. ivars should only ever get referenced
    directly in the constructor or their respective getter and setter
    methods.

    > Yes, it's kind of a pain. But he says that this protects you in
    > the future; if you end up actually needing to use an accessor
    > method then you can just modify the one that's already there
    > instead of trying to track down all the places you accessed the
    > variable directly. It's also better if you need to subclass in the
    > future, I imagine for the same reason.

    And often people eventually realize (well, some of them never do)
    that the pages really ought to be broken in to components.

    > It's not quite as much work as it sounds; if your variable is
    > named foo, and your getter and setter are foo() and setFoo()
    > respectively, WO will find and use them automatically. So you
    > don't have to change your bindings.

    Chuck

    -- 
    

    Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems. http://www.global-village.net/products/practical_webobjects



    This archive was generated by hypermail 2.0.0 : Tue Jul 03 2007 - 01:25:43 EDT