[Kde-games-devel] A design issue when using C++
Ian Wadham
ianw2 at optusnet.com.au
Sun Mar 15 02:55:53 CET 2009
Hi Kevin,
Thank you very much for your excellent and clear advice.
On Sat, 14 Mar 2009 9:43:34 pm Kevin Krammer wrote:
> On Saturday 14 March 2009, Ian Wadham wrote:
> > I have added a number of "helper" methods to the
> > KGrLevelPlayer class, while I have been hacking away at the KGrHero and
> > KGrEnemy code, but the methods are all <public>.
> >
> > That seems not at all elegant. It would make no sense, for example, for
> > the KGrGame class that creates a KGrLevelPlayer object to call these
> > "helper" methods. They are only meaningful in the context of a KGrHero
> > or KGrEnemy method. Of course, I can easily avoid such meaningless
> > calls in practice (and have done that) and so the code all works OK.
>
> Right, Since you are not exposing any public API, you don't have to worry
> too much about access restrictions.
>
I might leave it at that, for now, as I have lots of other code to work on.
> What you can easily do is to create a runner related "view" on your
> LevelPlayer object which contains only the methods needed for the runners.
> (potentially two different ones, one for the hero, one for the enemies).
> Then you pass a pointer to that to the runners instead.
>
> Since the LevelPlayer creates runners and the view object(s), it decides
> who to pass it to, who gains access to that methods.
>
> The simplest implementation of such views is to make their classes friends
> of the LevelPlayer so they can just forward the calls to the LevelPlayer
> instance.
>
Your suggestion and example are really neat. I must say that I had always
regarded the "friends" feature of C++ with some suspicion, as an enemy of
implementation hiding, but you have shown how to use it to "choose your
friends" and enhance hiding.
> Kevin Krammer, KDE developer, xdg-utils developer
> KDE user support, developer mentoring
>
Is "developer mentoring" a support group where people can discuss design
and programming concerns? I am retired and work alone at home and am
self-taught in Linux, KDE and C++, though I used to work a lot in Unix and C.
Sometimes I really miss having a workplace in which people can discuss
ideas about design and programming. Unfortunately for me, our local
Linux group is mostly Gnome users and sys admins and has no other
KDE development people. But it's very nice to be a man of leisure ... :-)
Thanks again, Ian W.
More information about the kde-games-devel
mailing list