Single responsibility principle

Hi! Just getting through this video Level Grid, around 5:40, and you suggest instead of opening up the entire workings of the GridSystem class, we should perform a pass through method to just get what we want, inside of the LevelGrid class.

My only concern here is the single responsibility principle you suggest in your videos on youtube. I have to ask, where do you draw the line? I understand no rule should be followed completely, but what I am really after here is understanding your methodologies when breaking these rules.

Programming principles are great, but sometimes they conflict.
In this case, The Single Responsibility principle is bumping up against the Law of Demeter

2 Likes

In this case the way I see it is more with regards to whether some other class should be aware that the LevelGrid uses a GridSystem in the background and I think the answer that makes most sense is no.

Other classes working with the LevelGrid shouldn’t care how the LevelGrid handles the grid data. Maybe it uses a sub-GridSystem, maybe it uses a Tilemap, maybe something else, so for the class interacting with the LevelGrid that shouldn’t matter.

With that logic it makes perfect sense to me that the LevelGrid is still responsible for just handling the level grid which includes passing through some data to the underlying GridSystem. I see that as still part of the LevelGrid’s responsibilities.

3 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms