How do I design a class that can switch between different implementations at runtime
I have a game where a Character class needs to change behavior from Villager to Enemy after certain conditions are met. I know I can't change an object's class at runtime in Java. What's the best pattern to achieve this instead. I've looked at Strategy pattern but that seems to change only algorithms not the whole behavior set. Should I use composition where the Character holds a reference to an interface like CharacterType and swap that reference when needed. Or is there a cleaner way using delegation. I want to avoid huge ifelse chains checking a state variable. Any code examples or pattern names would be really helpful. Thanks.