Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why Use Interfaces
Message
General information
Forum:
ASP.NET
Category:
Class design
Miscellaneous
Thread ID:
01278205
Message ID:
01280645
Views:
29
>You mean you have an application with only these 4 entities? ;)

No. I mean just four entities are enough to make Interfaces useful. The more you have the more useful (even neccessary) they become

>I think the point of your example is that, you have to use interfaces and MI, because your chosen entities are from different domains, but they have some common functions.
>What would be my class design? Let's say:
>
  EveryThings          EatMe(theObjThatEatsMe)
>    |- LivingThings         FeedMe(theObjFed), WaterMe(theObjWatered)
>    |    |- Person
>    |    |- Cow
>    |    |- Nightshade
>    |- NonLivingThings
>         | - Cake
>How do you know what's edible? I guess EatMe() will contain all logic you'd have in all interface implementations:
>
local llRetVal
>llRetval = .F.
>if this is a Nightshade
>    if theObjThatEatsMe is a Person that is not suicidal
>        llRetval = .F.
>    else
>        llRetval = .T.
>    endif
>else
>  llRetval = .T.
>endif
>if this is a Cow
>    if theObjThatEatsMe is a Person that is vegetarian
>        llRetval = .F.
>...
>
What if you have a dozen or so other farm animals as well as a Cow (Sheep,chicken, rabbit etc) Aren't you then going to have to change your code to 'If this is a cow or this is a chicken or this is a rabbit... ' (and change it every time you add another edible lifeform. So much easier to implement interfaces such a IEdible,INeedsWatering etc. and apply them the the relevant classes:
for each entity
if entity is IEdible
* eat it
endif
endfor

I'm afraid I don't see your arguments for a downside to Interfaces....
Regards,
Viv
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform