home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!fuug!demos!kiae!glas!demos!ucc.su.oz!extro.ucc.su.OZ.AU!maxtal
- From: maxtal@extro.ucc.su.OZ.AU
- Newsgroups: comp.lang.c++
- Date: 17 Jul 92 20:07 MDT
- Subject: Re: many set/get member functions in a
- Sender: Notesfile to Usenet Gateway <notes@glas.apc.org>
- Message-ID: <1992Jul17.160748.28162@ucc.su.oz>
- References: <1992Jul08.121838.13948@jho.com>
- Nf-ID: #R:1992Jul08.121838.13948@jho.com:2043735141:1992Jul17.160748.28162@ucc.su.oz:1351187194:001:2133
- Nf-From: extro.ucc.su.OZ.AU!maxtal Jul 17 20:07:00 1992
- Lines: 59
-
-
- In article <rmartin.711297034@thor> rmartin@thor.Rational.COM (Bob Martin) writes:
- >maxtal@extro.ucc.su.OZ.AU (John (MAX) Skaller) writes:
- >|
- >| In short, making the variable public is safer and more
- >| correct IMHO. Use get and set only under duress.
- >
- >I disagree. Under no circumstances should an instance variable be
- >directly manipulated by a client. To do so is to abandon the
- >abstraction of the server, and tie the clients hopelessly to its
- >implementation.
-
- No and yes respectively :-)
-
- The public variable ENFORCES a particular semantics,
- and if that happens to be the desired abstraction, use it.
-
- >
- >get/set functions are not much better, but every little bit counts.
-
- I contend that perhaps sometimes the ADVANTAGE of enforced
- semantics outweighs the disadvantage of loss of independence
- from representation: it does so when that abstraction
- corresponds directly to an existent type variable.
-
- >If you really and truly cannot find a way to get rid of your get/set
- >functions, then put them in, they are preferable to declaring your
- >member variables public.
-
- Not convinced. Where a change in implementation would
- ALWAYS be a change in semantics then the variables are best
- because the FORCE you to examine every use, as a change in
- semantics should.
-
- The get/set hides BOTH the semantics and the representation,
- the former is not desirable while the latter is.
- >
- >But, try hard to get rid of most of your get/set functions. They are
- >strong indicators of an incomplete abstraction.
- >
-
- Usually, yes. I agree in principle.
- There are SOME cases where a simple public data
- structure is useful. Quite a few, actually.
-
- Not all programming in C++ is OO.
-
- But for many abstractions, public data is not desirable.
-
- Proper semantics specification is, but that is not
- in the language, not even preconditions, invariants
- etc which Eiffel has.
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
-
-