This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Extension suggestions
- To: egcs at cygnus dot com
- Subject: Re: Extension suggestions
- From: Eric Christopher <echristo at cygnus dot com>
- Date: 20 Nov 1998 13:29:58 -0800
- Newsgroups: cygnus.egcs
- Organization: Cygnus Solutions
- References: <98112012533100.02876.cygnus.egcs@shadow1.shadow.sk>
ivan@shadow.sk (Ivan Schreter) writes:
> What is a property? Property is an extension of a field. Properties can
> be read-only, write-only or read-write. They serve for protecting class'
> fields from invalid accesses and can trigger actions on property read or
> write. Anyway, they are a neat thing. Consider this code:
>
[snip]
>
> Circle test;
>
> test.radius = 5;
>
> Now, you can access the radius of the circle using test.radius. When you set
> test.radius, it will actually generate call to setRadius(rvalue). When you read
> test.radius, it will generate read of private field f_radius. Or, there might
> be a function returning int associated with read, so read would call that
> function and return computed value. This way, some fields can be actually
> computed.
>
Okay. IMHO this is a very bad example. Basically what you are allowing
the property to do is violate the privateness of the f_radius member by
allowing other outside access than the protected routines that you already
had.
> As for default, it was in C++ Builder intended for builder API, so that
> visual (and other) components are initialized correctly when created. It
> might not be needed for the first implementation... Borland has also some
> more specifiers for property descriptions.
>
Essentially this originated in Delphi allowing people in a GUI to set
public:, protected:, and private: without having to code. If you are
just writing code then property is pretty much useless and could originate
in mistakes (IMHO of course) like the above snippet. I see some of the
usefulness that you see in these, but I can't really see how this would
be an advantage over properly thought out access routines?
I took a look at another example in C++ Builder also (cgrid.h), the main
use that I've seen it in there is for other objects to request information,
essentially duplicating a method that does the same thing.
-eric