C
C#5w ago
Asriela

Seeking Advice on Simplifying a Class with Multiple Operations on Data Pairs

This memory.cs class is a mess, is there a way to structure my code so that accessing data structures dont look so messy? Thank you in advance. https://gist.github.com/Asriela/d69bf1028644c1a3d5f5bef771727807
Gist
Memory class which is horrible
Memory class which is horrible. GitHub Gist: instantly share code, notes, and snippets.
9 Replies
Anton
Anton5w ago
the logic is fine, it's just that it's all piled up in one class you could group it up in some way maybe if some type of logic gets repeated, pull out that repeating part and reuse it you have a bunch of copy-pasted code there
FusedQyou
FusedQyou5w ago
For starters, organize the structure so fields are with fields (unless it's a backing field), properties with properties and methods with methods And half this content is not part of the actual Memory class so it should be in separate files imo
Asriela
AsrielaOP5w ago
Yeah i was just thinking im going to seperate it into different classes Like location manager , pricing manager ect
FusedQyou
FusedQyou5w ago
No I mean all those classes like ObjectTypeWorldObjectPair should for example go into ObjectTypeWorldObjectPair.cs
Asriela
AsrielaOP5w ago
But why? Its so little code So its ok to have tiny bits of code in their own files?
FusedQyou
FusedQyou5w ago
It comforms to The Single Responsibility Principle
FusedQyou
FusedQyou5w ago
DEV Community
SOLID: Single Responsibility Principle(SRP) in C#
Introduction When designing software, adhering to solid principles can make a huge...
FusedQyou
FusedQyou5w ago
You mention clutter. Things like this make the file much bigger than it has to be, and these classes have their own responsibility not directly tied to the Memory class
Asriela
AsrielaOP5w ago
thank you

Did you find this page helpful?