Storing a reference to the calling object

Tim t.oliver at windowslive.com
Sat May 23 20:53:38 UTC 2020


On Saturday, 23 May 2020 at 09:48:57 UTC, Mike Parker wrote:
> Since you're using classes, one way is to use a common base 
> class or an interface. But assuming "parent" is the owner of 
> the Sprite instance, you might eliminate the dependency on the 
> parent and have it update the Sprite's position when it's 
> updated instead of maintaining a position separately.
>
> class Parent {
>    private Sprite sprite;
>
>    void updatePosition(int x, int y)
>    {
>        sprite.x = x;
>        sprite.y = y;
>    }
> }

Thanks a lot for this. I was trying not to overcomplicate things 
this early in development but I think in me holding back I made 
things more complex then they needed to be.


More information about the Digitalmars-d-learn mailing list