SRP

Published March 06, 2021
Advertisement

Single Responsibility Principle

In OOP, SRP states that a class should have one and only one responsibility. Sounds simple, but in practice it can get complicated. In the engine so far I have struggled to keep game logic and graphics logic isolated. This has many benefits - I could for example change this to 3D at a later date if I wanted by deriving from the 2D sprite class, or otherwise change the way image and animation URIs get loaded and it would only have implications for the Valkyrie.Graphics library. The problem is that in the game page view model, those two abstractions must be integrated so they can be consumed by the model layer.

For the GameScreen class, the SRP is to draw a series of sprites where they are supposed to be drawn. But to do this right it must have a point of reference to know what game logic objects should be in frame. So far I have been approaching this clumsily, as each sprite is added. I think I have been stuck for so long because that is the wrong way. The gamepage view model has this information, so I think it will be necessary to make the gamescreen class (an object that resides in the gamepage view model) aware of a GL.Position (say, the lower left corner) to key everything else correctly. I have recently run through a deep debug dive of how these objects get constructed and the breakdown is simply that the GameScreen just doesn't have enough information to do this as easily as I want it to. I look forward to taking a fresh stab at this tonight. If I solve it, I will be in very good shape.

Previous Entry Update
Next Entry At long last
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement