Article View: comp.std.c++
Article #3869Re: Suggestion to the C++ standard
From: Jason D. Morris
Date: Sat, 30 Mar 1996 04:06
Date: Sat, 30 Mar 1996 04:06
45 lines
3053 bytes
3053 bytes
On 29 Mar 1996 09:07:43 PST, davidb@datalytics.com (David Bradley)
wrote:
>On the surface this sounds good. The obvious problem is the issue of
>access. You may want the a private set and public get.
>Another problem is you are unable to perform any validation within the
>set function.
The property class was designed to caputure the "get/set" pattern for
simple value types that need no validation. In his article, the
author explains that the idea originated with Delphi properties. It
posted this class in response to a discussion regarding adding
extensions to C++ to allow read/write access to member variables.
Basically, I wanted to point out that using a simple template class
you could accomplish the same thing the proposed extensions would
accomplish. If you only wanted a public get, you could take the
property template and create a new version called read_only_property
in which the set member not provided. I think that most of us would
agree that public data members are a bad thing and that acessing them
through function calls allows us to later change how the data members
are represented with out affecting client code.
>Lastly the naming of the data member/accessors breaks most common
>styles. Usually the member functions are distingiushed in some manner
>from the data members.
If you mean not explicitly naming the get/set functions with get/set
tacked on the beginning of the name then yes, I agree that the
property template breaks with common style. Personally, I never use
get/set prefixes in any of the code that I write. When I do have
members that perform get/set operations I overload member function
acessors with names like those used by the property class. Client
code should never rely on any internal class implementation details;
only interfaces to the services provided by the class.
Jason
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Technical Details
Message-ID:
<315cafc1.4316827@nntp.ix.netcom.com>Path:
arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austernReferences:
<4jatnm$s9b@post.tau.ac.il> <31599c95.4890732@nntp.ix.netcom.com> <315c0f6e.956220382@news.datalytics.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern From: jdmorris@ix.netcom.com (Jason D. Morris) Newsgroups: comp.std.c++ Subject: Re: Suggestion to the C++ standard Date: 29 Mar 1996 20:06:35 PST Organization: Netcom Approved: austern@isolde.mti.sgi.com Message-ID: <315cafc1.4316827@nntp.ix.netcom.com> References: <4jatnm$s9b@post.tau.ac.il> <31599c95.4890732@nntp.ix.netcom.com> <315c0f6e.956220382@news.datalytics.com> NNTP-Posting-Host: isolde.mti.sgi.com X-Original-Date: Sat, 30 Mar 1996 04:06:09 GMT X-NETCOM-Date: Fri Mar 29 8:05:17 PM PST 1996 X-Newsreader: Forte Agent .99d/32.182 X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBMVyzTEy4NqrwXLNJAQFuQgH/ZB4NGeEbwgWeuG92yN2G8mbYqCDex0a+ eDjUQQqemD+kxdAAPqfF1eoxuHwWMLMYkGXMpRNJ0rmmS5s/12S4jw== =Axy6 Originator: austern@isolde.mti.sgi.com