Calgarypuck Forums - The Unofficial Calgary Flames Fan Community

Go Back   Calgarypuck Forums - The Unofficial Calgary Flames Fan Community > Main Forums > The Off Topic Forum > Tech Talk
Register Forum Rules FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread
Old 09-29-2010, 03:22 PM   #61
yads
Powerplay Quarterback
 
Join Date: Apr 2008
Exp:
Default

Quote:
Originally Posted by BlackEleven View Post
There is no difference there. Those two things are functionally equivalent.

But to the second example I could add something like

protected String food;

Because my variable is protected I can control access to it. For example, I could make sure that the Eat method is the only way the dog's food can be consumed. I don't have to worry about some idiot using my class using dog.food to screw things up for me.

I don't have anyway of doing this with an interface where everything is public.
I think this is the wrong way about thinking of things. As developers we're typically not building libraries that are meant to be extended. Interfaces should be thought of as contracts or facades that consumers use. The fact that the details are hidden from consumers is just a byproduct.

Granted the example given, there is not much of a difference. It all depends on a larger context. Are animals being used somehow by other components of the system? It may make sense to go with the interface approach if IAnimal is used in the right context.

As my earlier image suggested it's hard to know when you're just starting to learn about these concepts. It takes years of experience before it starts to make sense, that's just the reality.
yads is offline   Reply With Quote
The Following User Says Thank You to yads For This Useful Post:
Old 09-30-2010, 10:08 AM   #62
yads
Powerplay Quarterback
 
Join Date: Apr 2008
Exp:
Default

I had a chance to think about it some more and I think a good rule of thumb that you may want to follow is if all you want to represent is a set of behaviors/properties then use an interface. If you want to define some of those behaviors, define some of the structure for inheritors, or save state then use abstract classes.
yads is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 07:38 AM.

Calgary Flames
2023-24




Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright Calgarypuck 2021