✅ Refactoring A Class With Too Many Responsibilities
Right now, I am trying to refactor a level editor class, which currently has way too many responsibilities, and I want to fix that. My core issue comes from trying to restrict access to certain methods between my level editor and other scripts. For example, here are methods for drawing a tile in a level (in my LevelEditor class):
-private DrawCommand (what to do when user issues a command to draw at the target position, including validation logic. Calls DrawWithLog)
-private DrawWithLog (try to draw a tile while logging changes to undo history, calls DrawAtRegion)
-public SmartDrawIngame (force draw, but also funnels logic through some singletons that may need to update internals, Calls ForceDrawIngame)
-private ForceDrawIngame (outside level edit UI, other scripts can request drawing at a specific spot using other private methods. Calls DrawAtRegion)
-private DrawAtRegion (actually erases anything that conflicts in different tilemaps, and draws. Calls SetTile)
-private SetTile (draw the tile and associated metadata)
There are several other features like this, and I want to split up responsibilities across a couple of classes (so I can also add other features). Any recommendation on how to split this without exposing everything publicly?
-private DrawCommand (what to do when user issues a command to draw at the target position, including validation logic. Calls DrawWithLog)
-private DrawWithLog (try to draw a tile while logging changes to undo history, calls DrawAtRegion)
-public SmartDrawIngame (force draw, but also funnels logic through some singletons that may need to update internals, Calls ForceDrawIngame)
-private ForceDrawIngame (outside level edit UI, other scripts can request drawing at a specific spot using other private methods. Calls DrawAtRegion)
-private DrawAtRegion (actually erases anything that conflicts in different tilemaps, and draws. Calls SetTile)
-private SetTile (draw the tile and associated metadata)
There are several other features like this, and I want to split up responsibilities across a couple of classes (so I can also add other features). Any recommendation on how to split this without exposing everything publicly?
