Well I think one should learn the basic OOP Pattern before going on to others.
OO isn’t a pattern. Data-driven and design by composition is pretty much the whole point.
Yeah. I love enums, but sometimes, I feel like it isn’t enough. You can do enums, or you can make a static class like minecraft does for blocks. Like, every block extends Block, and all blocks are predefined objects in it, like this:
class Block {
public static Block grass = ((Block) new Grass());
public static Block dirt = ((Block) new Dirt());
public Block(float hardness, int id) {
...
}
public abstract void render(Graphics g, float x, float y);
...
}
It seems to give more options than enums… Instead of just defining constructors, you can define methods as well!
But enums can have functions?
It really depends on what you want out of your program. Both are viable solutions, they both get the job done in different ways. However, you’ll need an actual class to host the enum, so depending on how you want your project to be set up, you’ll probably just need to go with static functions rather than an enum. If that makes sense! Typing on a phone is rather bad for going back over your post
The OP says he only needs to override data, so enums are the easiest way of doing things for this situation.
No need to worry about functions.
Using enums, anonymous inner classes, etc all require learning new language feature(s) AND they don’t scale very well and are pretty much only a minor step up from hardcoding (creating a sub-class for each monster). They can all be reasonable choices if the number of monsters is small, but why not do it one of the reasonable ways from the start?
Maybe I’m crazy but even for a beginner I’d suggest mimicking what you’d do in real life with a pencil-and-paper RPG. Let’s say you have a green-and-pink polka-dotted dragon fighting 10 rabies-infested-vorpal-furry-bunnies. You look up the “bunnies” in your Monsterz Emanuel do you expect to see:
rabies-infested-vorpal-furry-bunny
Is a vorpal-furry-bunny with “And they have rabies!” appended to the description. "+2% of inflicting “rabies” per hit appended to the attack description, etc.
Now you go lookup: vorpal-furry-bunny and they define how they are different from “furry-bunny” which is defined how it’s different from…
Nah, what you expect to see a complete description for pretty much every monster. Now when you proceed to play out he combat do you make 10 photocopies of the bunny description? Nope you jot down on a piece of paper the things that make each one unique (say its starting hit-points). You refer to the book when you need the definition and the piece of paper to track the changing information.
Monsterz Emanuel in code:
/** One instance of this class per monster defination (entry in Emanuel)*/
public class MonsterDesc
{
int maxHP;
int ar;
int dr;
int exp;
String desc;
}
An entry on the piece of paper in code:
public class Monster
{
MonsterDesc desc; // what kind of monster am I?
int hp;
}