Re: How much oop is too much oop?
- From: "David Webber" <dave@xxxxxxxxxxxxxxxxxxx>
- Date: Mon, 25 Apr 2005 21:50:19 +0100
"Gene Bushuyev" <gb@xxxxxxxxx> wrote in message
news:Nuabe.1202$zu.472@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> "ben" <benhongh@xxxxxxxxxxx> wrote in message
> news:426c6324$0$4659$afc38c87@xxxxxxxxxxxxxxxxxxxxxxx
> Stroustrup is right of course, why make function a member if it
> doesn't need
> to know the internal implementation? Why pay membership fees if
> you don't
> use the facilities?
I can't agree with this.
If a function always requires an instance of a class to work on,
then it may well be regarded as a method which is a property of that
class, and there is very often no point in it not being a member.
It costs nothing - there *are* no "membership fees".
Example consider a world with 4 shapes: round, square, triangular
and irregular with the last being anything other than the first
three
a.isRound() a.isSquare() a.isTriangular() may need the internal
representation but a.isIrregular() will just return true if all the
others are false. It could be implemented as a non-member if I go
for the above, but there is absolutely no reason to make it so.
And in fact if you want later to include a new possibility
a.isPentagonal() and redefine isIrregular() to exclude this new
case, then you'd have to change non-member functions also if
isIrregular() were not a member, and you have effectively lost one
of the prime advantages of encapsulation.
Dave
--
David Webber
Author MOZART the music processor for Windows -
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mzusers/mailinglist.htm
.
- Follow-Ups:
- Re: How much oop is too much oop?
- From: ben
- Re: How much oop is too much oop?
- From: Nemanja Trifunovic
- Re: How much oop is too much oop?
- From: Gene Bushuyev
- Re: How much oop is too much oop?
- From: Gene Bushuyev
- Re: How much oop is too much oop?
- References:
- How much oop is too much oop?
- From: ben
- Re: How much oop is too much oop?
- From: Gene Bushuyev
- How much oop is too much oop?
- Prev by Date: Re: !_Re: Why not top posting?
- Next by Date: Re: Why not top posting?
- Previous by thread: Re: How much oop is too much oop?
- Next by thread: Re: How much oop is too much oop?
- Index(es):