Is this a wasteful / poor design for using a vector / list, where in most cases will it have only one element?
Example:
class dragon
{
ArrayList<head> = new ArrayList<head> Heads;
tail Tail = new tail();
body Body = new body();
dragon()
{
theHead=new head();
Heads.add(theHead);
}
void nod()
{
for (int i=0;i<Heads.size();i++)
{
heads.get(i).GoUpAndDown();
}
}
}
class firedragon extends dragon
{
}
class icedragon extends dragon
{
}
class lightningdragon extends dragon
{
}
class hydra extends dragon
{
hydra()
{
anotherHead=new head();
for (int i=0;i<2;i++)
{
Heads.add(anotherHead);
}
}
}
class superhydra extends dragon
{
superhydra()
{
anotherHead=new head();
for (int i=0;i<4;i++)
{
Heads.add(anotherHead);
}
}
}
EDIT: (part 2 of the question)
Thanks for answers. They were very helpful. I actually came across this situation more than once, and I would like to give a second example that is not related to inheritance. This is really a real example, and although I decided that my current project is small enough to be safe using vectors based on your answers, this is a concept that I assume I will use on a much larger scale at some point.
Android, Imagepoint, XY-, -. , , , , , .. xy , , xy .
. , - , - .. , , , , .
- , , , : , .. , , , / - . , , , , . ?