p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Microsoft Visual C# 2008 ISBN: 978-0-470-19135-4
This is the forum to discuss the Wrox book Beginning Microsoft Visual C# 2008 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, Eric White; ISBN: 9780470191354
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Microsoft Visual C# 2008 ISBN: 978-0-470-19135-4 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other programmers’ questions, win occasional prizes given to our best members, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 18th, 2009, 08:14 AM
Registered User
Points: 11, Level: 1
Points: 11, Level: 1 Points: 11, Level: 1 Points: 11, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2009
Location: Warsaw, Poland / DE, USA
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb Understanding Interfaces

So I'm having a bit of a tough time understanding Interfaces. On page 199 we have an example:
Code:
Cow myCow = new Cow();
Chicken myChicken = new Chicken();
IConsume consumeInterface;
consumeInterface = myCow;
consumeInterface.EatFood();
consumeInterface = myChicken;
consumeInterface.EatFood();
And i wondered to myself -- why would i want to do any of this? So I asked for help from a C++ programmer.
Can someone please let me know if i understand this correctly now?
  • An interface is a contract - by implementing an interface, i agree to implement all the functions in that interface for my class.
  • Interfaces in C# are a way to do multiple inheritance that's available in C++
  • By assigning an object reference (as above) to an interface variable type, I'm basically using polymorphism like normal, but with C# i can't have multiple inheritances, so i need to do it with an interface.

And that's pretty much it, right? If anyone can shed further light on this, i'd greatly appreciate it.

As much as I enjoy Wrox books, i think the chapters devoted to OOP, polymorphism and Interfaces lack a lot as far as making the reader understand. The how is explained, but not the why...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Two interfaces with Same function name Manoj Bisht C# 2005 5 March 25th, 2009 10:52 AM
returning interfaces mike72 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 April 17th, 2008 06:53 AM
interfaces malli_kv2 Java Basics 1 April 23rd, 2007 06:21 AM
[CH04] Interfaces Norm 2782 BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 3 June 16th, 2005 05:56 AM
Polymorphism with Interfaces digby_dog VB.NET 2002/2003 Basics 2 May 11th, 2005 01:50 PM



All times are GMT -4. The time now is 12:35 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
© 2010 Wiley Publishing, Inc