Czy opłaca się go stosować dla samej przejrzystości czy np w przykładzie poniżej lepiej z niego nie korzystać i po prostu dać klasom podrzędnym klasie Creature voidy? to tak na szybko napisałem tylko dla pokazania mojego dylematu :D
mam taki prosty interfejs:
Kod:
interface Functions
{
void getStatistics();
}
Kod:
class Creature
{
int health;
int outfitID;
int speed;
public Creature()
{
health = 100;
outfitID = 1;
speed = 10;
}
public int Health
{
get
{
return health;
}
set
{
if(health != value)
{
health = value;
}
}
}
public int OutfitID
{
get
{
return outfitID;
}
set
{
if(outfitID != value)
{
outfitID = value;
}
}
}
public int Speed
{
get
{
return speed;
}
set
{
if(speed != value)
{
speed = value;
}
}
}
}
class Player : Creature, Functions
{
int mana;
int level;
public Player()
{
mana = 100;
level = 1;
}
public int Mana
{
get
{
return mana;
}
set
{
if(mana != value)
{
mana = value;
}
}
}
public int Level
{
get
{
return level;
}
set
{
if(level != value)
{
level = value;
}
}
}
public void getStatistics()
{
Console.WriteLine("Type: Player");
Console.WriteLine("Health: " + Health);
Console.WriteLine("OutfitID: " + OutfitID);
Console.WriteLine("Speed: " + Speed);
Console.WriteLine("Mana: " + Mana);
Console.WriteLine("Level: " + Level);
}
}
class Monster : Creature, Functions
{
int spellPower;
int attackspeed;
public Monster()
{
spellPower = 1;
attackspeed = 100;
}
public int SpellPower
{
get
{
return spellPower;
}
set
{
if(spellPower != value)
{
spellPower = value;
}
}
}
public int Attackspeed
{
get
{
return attackspeed;
}
set
{
if(attackspeed != value)
{
attackspeed = value;
}
}
}
public void getStatistics()
{
Console.WriteLine("Type: Monster");
Console.WriteLine("Health: " + Health);
Console.WriteLine("OutfitID: " + OutfitID);
Console.WriteLine("Speed: " + Speed);
Console.WriteLine("SpellPower: " + SpellPower);
Console.WriteLine("AttackSpeed: " + Attackspeed);
}
}
Zakładki