I consider myself past the beginners stage but not quite ready for a full time gig. My goal is to become a developer, but since I am pretty much completely self-taught, I'm having trouble going from that intermediate level to a point where an employer would feel confident in hiring me on even as a Junior Dev.
Either way, I determined that having some sort of a portfolio would be required. With that decided, I embarked on creating a program that is based on my love and enjoyment of pen & paper roleplaying games. I'm creating an application that will make it easier for the storyteller of the game to create encounters for the players and so forth since the game is pretty math-heavy and complicated. This made me think it would be perfect for reinforcing programming concepts. I am gearing this to end up with some sort of UI, whether it be JavaFX or even turned into an Android app. I would like my portfolio projects to showcase my understanding of OO design.
That said, I'm having trouble designing classes after learning that I should probably avoid using getters/setters (see
http://www.javaworld.com/article/2073723/core-java/why-getter-and-setter-methods-are-evil.html). I have a Character class used to represent a character in the game. This class has several fields: Ability attributes such as Strength, Dexterity, etc, the character's chosen character class (Fighter, Barbarian, Wizard, etc...), the character's skills which have allocated points as selected by the player, equipment and items, and basic fields like how many health points they have for example. I would also like to grant the ability of the user to save data.
The problem I have is trying to figure out how I can avoid using getters/setters while also allowing for the changes that will happen as the game goes on. Eventually the character will level up after gaining X number of experience, so they might have improvements to one of their ability scores (Strength for example). They may pick up a magic item that temporarily improves a score so long as they have it in their possession (not permanent). I've read that you shouldn't sit down with a preconceived class to build around, but Character seems to make the most sense for this since just about all of its internal variables will change at some point and they need to be kept track of. I'm not sure how else to go about doing that, but that might simply be my ignorance.
Here's basically what I have so far:
I am using the Factory
pattern in order for the user to select which character class or race (Dwarf, Elf, etc...) for their character. Skills will be updated as the character levels, and ability scores (STR, etc...) can be altered and modified. Based on the character's chosen race, their ability scores are modified, though that is a permanent adjustment. Some aspects of a character should be changeable, but others shouldn't. They won't be able to change race without creating an entirely new character, for example. But, initially that should be something that can be changed as the character is being created.
I'm trying to design the class so that all of the field objects (STR, skills, charClass, race, etc...) are doing the work and keeping track of their own state. Is the above good OO design? Originally I had the Character class doing and keeping track of everything and after more experience/knowledge gathering, I made the non-primitives objects of their own.
Maybe I really need to brush up on my thinking as it relates to OO because in my mind, I'm having a hard time balancing immutable classes and encapsulation with changeable fields or objects. Do you just set it up to create an entirely new object each time you need to alter a field, such as if a Character picks up a magic belt which boosts his Strength score, you create an entirely new Strength object to assign to the Character object, or create an entirely new Character object with that one change to the Strength object? I have a good feeling that's not the case, but I still have difficulty with the idea.
I probably need to do some reading, but I find I learn best by doing, and so I was looking for a little guidance as it relates to my current project. I am definitely all ears when it comes to book suggestions though. Any guidance or pointers anyone can offer would be greatly appreciated.