Note that this is not an inheritance or interface.
I have a class HP
public class HP
{
public int Base;
public int Value
{
get
{
//Need to access Monster.Level to calculate total HP.
}
}
}
And a class Monster calling HP
public class Monster
{
public HP hp;
public int Level;
}
How can I access Monster.Level from HP?
I tried to pass Level by reference to HP upon instantiating.
public class HP
{
private ref int Level;
public A(ref i)
{
Level=i;
}
}
But I want to keep A as simple and clean as possible.
The reason I don't want to pass the level upon creation is Level is a constantly changing valuable, I'll will then have to "update" the HP every time the monster gains a level or something, which is NOT a efficient way to do things.
And there are other things accessing Level, such as Attack and Damage, etc.
I currently has a method within HP, Attack, Damage, etc., taking the Level as a parameter.
public int Value(int lv)
{
return Base+10*lv;
}
But according to the a little bit of SOLID principle I know, this is a VERY BAD coding!