Go Back   ZeroC Forums > Comments

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 10-10-2008
joshmoore joshmoore is offline
Registered User
 
Name: Josh Moore
Organization: Glencoe Software, Inc.
Project: OMERO, http://trac.openmicroscopy.org.uk/omero
 
Join Date: Feb 2007
Location: Germany
Posts: 59
Minor RFE : Additional accessor metadata for use with protected

We are in the process of converting many of our classes classes to "protected" for immutability (among other application-centric reasons).

The most straightforward way would be an ["immutable"] or ["const"] directive at the class level, which would require there to be a getter generated for each field. However, there may be some internal reason that classes can't be immutable in Ice.

So, at the moment we're looking to use a combination of ["java:getset"] and ["protected"] in Java. The combination provides a convenient solution. First, "getset" can be used to have the accessors in place while developers upgrade. "protected" can then be added to force use of the accessors. And finally, "getset" can be removed and only the getters implemented to have immutable types.

I haven't used the C# mapping extensively, but I imagine the "property" directive would allow for a similar migration path.


Would it be possible to have similar directives in the other languages?


We began using Ice before "protected" was added and the cost of migrating to non-public fields has been fairly high. Having accessors generated automatically with the "protected" metadata costs little initially (other than the extra method invocation) with the option of manually implementing the accessors later for immutability or even "laziy-loaded" semantics.

One note: when using "protected" in the python mapping, a __getattr__ method can also be generated in addition to the accessors to prevent any code changes:

Code:
      def __getattr__(self, name):
          """
          Reroutes all access to object.field through object.getField() or object.isField()
          """
          field  = "_" + name
          capitalized = name[0].capitalize() + name[1:]
          getter = "get" + capitalized
          questn = "is" + capitalized
          if hasattr(self, field):
              if hasattr(self, getter):
                  method = getattr(self, getter)
                  return method()
              elif hasattr(self, questn):
                  method = getattr(self, questn)
                  return method()
          raise AttributeError("'%s' object has no attribute '%s' or '%s'" % (self.__class__.__name__, getter, questn))
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Minor RFE : Property expansion joshmoore Comments 4 06-10-2008 06:46 AM
slice2cppe metadata Oscar.Acena Help Center 6 07-16-2007 11:09 AM
Ice 3.2.0 migration: protected class destructors stephan Help Center 4 06-01-2007 03:57 PM
Metadata directives bartley Help Center 1 02-03-2006 02:35 PM
c++ metadata sylvain Help Center 5 08-06-2003 10:10 AM


All times are GMT -4. The time now is 09:59 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
(c) 2008 ZeroC, Inc.