Reputation: 15
sorry i don't know how to write my problem in couple words, so i couldn't even properly google it.
thing is: i have chain of abstract classes.
AbEntity with abstract properties.
AbHero and AbEnemy with realization of AbEntity's properties and with it's own abstract properties
Non-abstract classes.
For some reason non-abstract classes should have their realization of AbEntity's abstract properties. Why can't they take it from parents (AbHero & AbEnemy)?
I don't understand how to make this architecture without abstract classes, but i don't want to write 7 extraproperties with return base.PropName; in every non-abstract class :(
Interface wont work because i need to use fields. (it's unity)
Upvotes: 1
Views: 611
Reputation: 15982
Your questions isn't clear, so I just show you how declare a 3-level hierarchy.
A abstract base class with one abstract property:
abstract class AbEntity
{
public abstract int PropertyEntity { get; }
}
A derived still abstract class with an implementation of PropertyEntity
and another abstract property added.
abstract class AbHero : AbEntity
{
public override int PropertyEntity { get { /* ... */ } }
public abstract string PropertyHero { get; }
}
A non derived class implementing the remaining abstract properties (just PropertyHero
, not PropertyEntity
)
class NonAbstractHero : AbHero
{
public override string PropertyHero { get { /* ... */ } }
}
Upvotes: 0
Reputation: 15151
For some reason non-abstract classes should have their realization of AbEntity's abstract properties.
That's not true, if they inherit of abHero and abHero already implements the abstract AbEntity properties then there's no need to implement them again, look at this example:
public abstract class a
{
public abstract int value{ get; }
}
public abstract class b : a
{
public abstract int valueb { get; }
public override int value
{
get { return 1; }
}
}
public class c : b
{
public override int valueb
{
get { return 2; }
}
}
Upvotes: 1