[Kde-games-devel] A design issue when using C++

Inge Wallin inge at lysator.liu.se
Mon Mar 16 11:48:21 CET 2009


On Saturday 14 March 2009 11:43:34 Kevin Krammer wrote:

> A bit like this:
>
> class EnemyView
> {
>   friend class LevelPlayer;
>
> public:
>   Directiony getDirection( int i, int j )
>  {
>     return mLevelPlayer->getEnemyDirectiony( i, j );
>   }
>
> private:
>   // Level Player is our friend and can thus call the private constructor
>   // Nobody else can create instances of the view
>   EnemyView( LevelPlayer *levelPlayer ) : mLevelPlayer( levelPlayer ) {}
>
>   LevelPlayer *mLevelPlayer;
> };
>
> class LevelPlayer
> {
>   friend class EnemyView;
>
> public:
>   LevelPlayer() :mEnemyView( new EnemyView( this ) )  {}
>
>   void init()
>   {
>     Enemy *enemy = new Enemy( mEnemyView );
>   }
>
> private:
>   EnemyView *mEnemyView;
>
>   Direction getEnemyDirection(int i, int j);
> };

Isn't this the classic Facade design pattern?  We have something similar in 
Marble where we have a read-only facade to the main marble data store called 
MarbleDataFacade.  I suggest you name your class not ...View, but ...Facade 
instead.

(You can of course take a look at Marble to see the details there.)

	-Inge




More information about the kde-games-devel mailing list