[Exceptional C++ Style] Item 17 - Encapsulation
solosnake .
solosnake at hotmail.com
Mon Dec 20 10:01:51 EST 2004
>From: "Adrian Fagg" <adrianf at evaluategroup.com>
*snip*
> > -----Original Message-----
> > From: effective-cpp-bounces at accu.org
> > [mailto:effective-cpp-bounces at accu.org]On Behalf Of solosnake .
> > Sent: 20 December 2004 13:12
>
> > // Case 1 : Encapsulated data.
> > class Case1
> > {
> > public:
> > const SomeData& GetSomeData()const;
> > private:
> > const someData_;
> > };
> >
> > // this could also be inlined instead.
> > const SomeData& Case1::GetSomeData()const
> > {
> > return someData_;
> > }
>
>Hey, hold on - that's giving you a pretty strong dependency on its
>internals
>as well isn't it?
>
>Regards,
>
>Adrian
The dependancy is purely on the class / implementation side - there is *no*
dependancy for the end user of my class - this is the important difference.
As an example, lets imagine you and I are co-operating on a project - I am
writing the class that provides you with the 'SomeData' you need. If I
provide you with access to it via an accessor function, then your code
doesnt need any changes when at a later date I need to make changes to the
internals of my class. With this in mind, is the differance clear? Perhaps
we are focusing too much on authoring the class code, and ignoring the user
of the class?
Cheers,
Daire
More information about the Effective-cpp
mailing list