Using interfaces will not work because I want one implementation. Using this solution will end with a lot of redundant code, because I plan to have quite a few subclasses (composition versus inheritance). I decided that a solution for specific tasks is what I am looking for, and I cannot come up with anything elegant.
Basically, I want classes to have separate properties, and for those properties that should be bound at design time to any subclass that I choose. Say I have a ninja class. I would like to be able to do arbitrary subclasses such as "gray ninja", where a gray ninja will always have a sword and throw stars. Then maybe redNinja, who will always have a sword and cloak. Obviously, swords, stars and capes will have their own implementation - and here I can not use interfaces. The closest solution I could find was a decorator template, but I do not want to use this functionality at runtime. Is branching the best solution? Where inside the Black Ninja class constructor do I pass it through the sword constructors and throwing the Star? (those that are abstract classes)
not encoded at the time, and the reading didn't go too far - forgive me if the answer is simple.
Edit: Answered my own question. I cannot mark this as an “answer” until tomorrow. Please let me know if there is a problem with this that I did not catch. All reading this issue made me make it awesome. Learned quite a bit.
source
share