D modeling

Jesse Phillips Jesse.K.Phillips+D at gmail.com
Sun Jul 7 16:37:32 UTC 2019


On Friday, 5 July 2019 at 11:22:10 UTC, CheeseWiz wrote:

> You seem to think the example is a real world model and that 
> all other models would work the same.

No I asked a question about your model and you said it couldn't 
be done without interfaces, I showed that wasn't the case.

>
> You've removed all the interfaces so you would not have MI. You 
> believe that was as smart thing. But you have completely 
> disconnected  ModelB from itself.
>
> Now ModelB.Dog does not inheret from ModelB.Animal.

Your model doesn't do that either, why? Because D doesn't have 
multiple inheritance. You would need `ModelB.Dog : ModelB.Animal, 
ModelA.Dog` but you can't because D does not allow for it.

> 2.
>
> My original code:
>
> 	ModelA.iAnimal animal1 = new ModelB.Cat("Super Mittens");
> 	ModelA.iAnimal animal2 = new ModelB.Dog("Super Sparky");
>
> you changed the returns to auto.

You are correct, and that only has the effect of forcing the cast 
I removed, my model matched the behavior of your model.


> 3. You have to realize you are wrong, that is the first step to 
> understanding. I've tried to point it out but you are probably 
> still thinking "But I'm right and he's wrong".

No, I don't think I am right, I think I was wrong because the 
model you provided was inaccurate for requirements you are 
placing on me.

A wise man once said to me, "You have to realize you are wrong, 
that is the first step to understanding"

See, what happened is you missed the point of removing all the 
interfaces, it was to show that the interfaces you chose to add 
were not necessary to meet the code you had put into place, it 
was also intended to show that your inheritance of all the 
different interfaces in all classes was excessive and causing 
issues.

Here is a more accurate representation of your model when 
correctly written in D.

https://gist.github.com/JesseKPhillips/b891604444f4aee72c705b498a206d50

What you will notice is that the ModelB.Animal class is commented 
out, the reason for this is because it is not utilized your 
original model as you never inherited that class, all you did was 
`alias Attack = Animal.Attack;` but that isn't doing what you 
think it is doing.

I instructed ModelB.iAnimal to `override iFood LikesWhichFood()` 
because I wanted covariance and have ModelB Animials to return 
ModelB.iFood.

So please continue to insult my understanding of how D 
inheritance works, I'd like to hear more about your unbounded 
knowledge.


More information about the Digitalmars-d mailing list