4 ms·
is_immune_to_poison. is_resistant_to_fire. reflects_magic :only => :fire. I find that a touch inscrutable, but to make an object have various behaviors certain
by mynameishere 19y ago
is_immune_to_poison. is_resistant_to_fire. reflects_magic :only => :fire.
I find that a touch inscrutable, but to make an object have various behaviors certainly doesn't require subclassing.
obj.addProperty(new PoisonImmunity());
obj.addProperty(new FireResistence());
obj.addProperty(new ReflectsMagic());
or, in one line:
obj.addProperties(new PoisonImmunity(), new FireResistence(), new ReflectsMagic());
or, super-fast mode:
obj.addPropertyFlags(POISON_IMMUNITY | FIRE_RESISTENCE | REFLECTS_MAGIC);
or, pulling from some configuration file:
obj.addProperties("poison_immunity", "fire_resistence", "reflects_magic"));
...maybe you're doing something I don't grasp, but it seems like another case of pretending that java has a disability that it doesn't.
- qaexl 19y agoNo, I'm talking about something different. I don't know Javascript well enough to toss off something, but the equivalent in Ruby looks like this: class MyBadassSword < GameObject is_immune_to_poison is_fire_resistant reflects_magic end When is_immune_to_poison is called, it reopens MyBadassSword and attaches more code to it. This is not a syntax feature of Ruby so much as using .include to append more code modules or rewrite definitions to it. The Java JVM supports this, but you have to jump through a lot of hoops to do that with Java itself. The POISON_IMMUNITY | FIRE_RESISTENCE | REFLECTS_MAGIC is exactly what I don't want to mess with. I'm not instantiating PoisonImmunity() class. I'm not using bit fields like POISON_IMMUNITY. (I specifically said in my previous post I was not talking about bit fields). I'm not talking about pulling strings from a configuration file.