Which player class is created by better hierachy?
-
26-06-2021 - |
Domanda
Which class is more acceptable for future implementations? Assault predator(multiple inheritance) or queen(multi-level hierarchy)?
#include "stdafx.h"
#include<stdlib.h>
class living
{
public:
int hitpoints;
int adaptation;
};
class alien:public living
{
public:
bool tail;
bool claws;
bool legs;
bool secondary_jaws;
bool acid_blood;
alien(){adaptation=1000;hitpoints=50;}
};
class queen:public alien
{
public:
bool ovipositor;
bool tertiary_jaws;
};
class predator
{
public:
bool legs;
bool arms;
bool glowstick_blood;
};
class assault_predator:public living,public predator
{
public:
bool plasma_caster;
bool infrared_vision;
assault_predator(){hitpoints=150;adaptation=33;}
};
int main()
{
assault_predator player1;
queen player2;
getchar();
return 0;
}
As seen, assault predator is derived from living and predator separately. Queen is derived from alien and alien is derived from living.
Question: Which one is more logical in terms of programming and class hierarchy.
What are cons&pros of these players?
Soluzione
They are just different. Multiple inheritance allows you to combine separate objects into one. Multi-level inheritance allows further specification of type.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow