General problem I'm having in D with the type system
JN
666total at wp.pl
Sun May 27 18:16:25 UTC 2018
On Sunday, 27 May 2018 at 06:00:30 UTC, IntegratedDimensions
wrote:
> animal a = new cat();
>
> a.f = new food()
> auto c = cast(cat)a;
>
>
> as now f in cat will be food rather than catfood.
I think the problem is in your hierarchy. If Animal can have
Food, that means that any animal should be able to accept any
food, without knowing what kind of food is this. Cat requiring
cat food is a leaky abstraction, the cat shouldn't know nor care
what kind of food it gets, as it's an animal and it will eat any
food.
More information about the Digitalmars-d
mailing list