How to organize by SOLID?

Joined
Apr 19, 2020
Messages
7
Programming Experience
1-3
Hello, everyone. I’m having a hard time understanding the proper structure of the project, who’s responsible for what.

Can you help me with a specific example?

We have a class of "CoinSystem" for example, this class for create coins on a level. What class should be responsible for counting collected coins and displaying them on a screen? Same class "CoinSystem" ? Or must be a separate class of "LevelStatistic". According to SOLID principles, a class should have one responsibility and one reason to change, "CoinSystem" already has it.

At the end of the level, i have to calculate the amount of coins and the time spent.

And maybe you have an example of a project in GIT where i can look at architecture, structure and interaction.
 
a class should have one responsibility and one reason to change, "CoinSystem" already has it.
Really? To me it feels like your CoinSystem class has a lot of responsibilities:
  • create coins on a level
  • counting collected coins
  • displaying them on a screen

Here's one way to think of things: Lets say you put each your classes into it's own DLL, and each DLL was 1GB big, and all your users of had to download all the classes to their computer to be able to run your game. Now you come up with a new feature: make the coins sparkle when displayed on the screen. What DLL would you have to touch and make your users download again? In your situation, it would be CoinSystem.dll. Now you created a brand new kind of coin: a MegaBuck coin. What DLL would you have to touch and your users have to download again? CoinSystem.dll again? But as far are you users know from the last time they downloaded, CoinSystem.dll was making coins shiny, not necessarily to get a MegaBuck. What if they want to have the MegaBuck, but they don't like the shiny look?
 
And maybe you have an example of a project in GIT where i can look at architecture, structure and interaction.
How would we have an example of any such code? It's your project.

If you want help with your project, then you post your own code here and explain the problem with it, and we can try to help you to structure it appropriately. For the most part, your class should only have one purpose, and only one. If you need to, you can also use inheritance from other classes where they need to access your main base class for your coinsystem. Whatever way you write your code, you should ensure it's reusable in an object orientation sense, and pass it around your project, normally using isp as needed. There are a few articles which cover this online. Perhaps you should first try searching through the interwebs or start here with : SOLID Design Principles Explained Using C#

Do you have a specific question about code that you've written? If not, I advise doing your own research into examples that may exist on this subject in order for you to get some ideas from. We don't write free code for people, nor do we do your research for you. If you are willing to pay people for such services, we have a forum for that here : Projects for Hire If you have code that you've written and need help with, then I suggest post that code (in code tags), and maybe we can advise some changes. That's how it works on here. :)
 
Back
Top Bottom