Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 18th, 2009, 07:14 AM
Registered User
 
Join Date: Sep 2009
Posts: 4
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...





Similar Threads
Thread Thread Starter Forum Replies Last Post
Two interfaces with Same function name Manoj Bisht C# 2005 5 March 25th, 2009 09: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 05:53 AM
interfaces malli_kv2 Java Basics 1 April 23rd, 2007 05:21 AM
[CH04] Interfaces Norm 2782 BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 3 June 16th, 2005 04:56 AM
Polymorphism with Interfaces digby_dog VB.NET 2002/2003 Basics 2 May 11th, 2005 12:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.