Re: Too many datamembers
On Nov 13, 8:22 am, Michael DOUBEZ <michael.dou...@free.fr> wrote:
Maxim Yegorushkin a =E9crit :
On Nov 12, 3:04 pm, James Kanze <james.ka...@gmail.com> wrote:
On Nov 12, 11:42 am, Maxim Yegorushkin <maxim.yegorush...@gmail.com>
wrote:
On Nov 12, 3:11 am, sreeni <sreeni.h...@gmail.com> wrote:
I have a ordinary C++ class with lot of datamembers used
internally between methods of the same class.
Is there any other elegant way to maintain the private
datamembers.
The most elegant way is to hide the implementation details of
your class. All non-public members are an implementation
detail. You hide these by providing an abstract class /
interface and a factory function that creates an instance of
that interface.
That's one way. The more idiomatic way in C++ is the
compilation firewall idiom.
How do you tell which one is more idiomatic?
The factory system requires that everything be put on the heap and use
mechanisms to dispose of it and ensure exception safety; whereas the
firewall idiom let you instantiate the class as any other and dynamic
allocation is handled internally/locally.
In this regard, the firewall idiom is a far better tradeoff for the
intended usage here.
True. In this case you just modify the class, but not users.
--
Max