KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm making a role playing game just for fun and to learn more about the SOLID principles. One of the first things I'm focusing on is SRP. I have a "Character" class that represents a character in the game. It has things like Name, Health, Mana, AbilityScores, etc. Now, normally I would also put methods in my Character class so it would look something like this... public class Character { public string Name { get; set; } public int Health { get; set; } public int Mana { get; set; } public Dictionary<AbilityScoreEnum, int>AbilityScores { get; set; } // base attack bonus depends on character level, attribute bonuses, etc public static void GetBaseAttackBonus(); public static int RollDamage(); public static TakeDamage(int amount); } But because of SRP I've decided to move all the methods out into a separate class. I named that class "CharacterActions" and now the method signatures look like this... public class CharacterActions { public static void GetBaseAttackBonus(Character character); public static int RollDamage(Character character); public static TakeDamage(Character character, int amount); } Notice that I now have to include the Character object I am using in all my CharacterActions methods. Is this the right way to go about leveraging SRP? It seems to go completely against the OOP concept of encapsulation. Or am I doing something completely wrong here? ONE thing I do like about this is that my Character class is very clear on what it does, it simply represents a Character object.
Tags (comma-separated)
Save Edits
Cancel