Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to design around lack of multiple inheritance?
    primarykey
    data
    text
    <p>Using interfaces won't work because I want a single implementation. Using <a href="https://stackoverflow.com/questions/3849097/how-to-simulate-multiple-inheritance-without-interfaces">this</a> solution would end in a lot of redundant code because I plan on having quite a few sub classes (composition vs inheritance). I've decided that a problem-specific design solution is what I'm looking for, and I can't think of anything elegant.</p> <p>Basically I want classes to have separate properties, and for those properties to be attached at design time to any sub class I choose. Say, I have class 'ninja'. I would like to be able to make arbitrary sub classes such as 'grayNinja' where a gray ninja will always have a sword and throwing stars. Then possibly 'redNinja' who will always have a sword and a cape. Obviously swords, stars, and capes will each have their own implementation - and this is where I can't use interfaces. The closest solution I could find was the <a href="http://en.wikipedia.org/wiki/Decorator_pattern" rel="nofollow noreferrer">decorator pattern</a>, but I don't want that functionality at runtime. Is the best solution an offshoot of that? Where inside the Black Ninja class constructor, I pass it through the constructors of sword and throwingStar? (those being abstract classes)</p> <p>haven't coded in a while and reading hasn't gotten me too far - forgive me if the answer is simple.</p> <p><strong>Edit:</strong> Answered my own question. I can't mark it as 'answer' until tomorrow. Please let me know if there's a problem with it that I didn't catch. All the reading this problem forced me to do has been awesome. Learned quite a bit.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload