Skip to main content
6 events
when toggle format what by license comment
Mar 11, 2014 at 22:10 comment added supercat @pdr: It may be worthwhile to define IHasSuperPower, but it's also necessary to define IAnimalWithSuperPower (and for animals that implement IHasSuperPower to also implement IAnimalWithSuperPower), because for a reference to be usable as both IAnimal and IHasSuperPower, it must be of a type that derives from both.
Jul 29, 2013 at 13:52 vote accept Jesse Webb
Jul 26, 2013 at 22:12 comment added pdr @Cameron: Close, but I wouldn't call IAnimalWithSuperPower. There's nothing to say that every object implementing that interface must be an animal. Stick with IHasSuperPower.
Jul 26, 2013 at 22:09 comment added pdr @JesseWebb: Neither. Prefer composition over inheritance. Put all your repeated code in a service and inject that into each animal that needs it.
Jul 26, 2013 at 20:52 comment added Jesse Webb In my trivial example code, the only functionality which I desire to share is the SuperPower property. Unfortunately, in my real-world problem, the AnimalWithSuperPower abstract class has several properties and methods which I want inherited by all the children. That being said... I am not sure which I prefer: needing multiple pass-through calls for all childrens' behaviour OR re-declaring the abstract behaviour repeatedly in all children. Which is the lesser of 2 evils? LOL
Jul 26, 2013 at 20:45 history answered Cameron CC BY-SA 3.0