Book Image

Learning Object-Oriented Programming

By : Gaston C. Hillar
Book Image

Learning Object-Oriented Programming

By: Gaston C. Hillar

Overview of this book

Table of Contents (16 chapters)
Learning Object-Oriented Programming
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Interfaces and multiple inheritance in C#


You can think of an interface as a special case of an abstract class. An interface defines properties and methods that a class must implement in order to be considered a member of a group identified with the interface name.

For example, in C#, the language that supports interfaces, we can create the IAlien interface that specifies the following elements:

  • The NumberOfEyes property

  • The parameterless method named Appear

  • The parameterless method named Disappear

Once we define an interface, we can use them to specify the required type for an argument. This way, instead of using classes as types, we can use interfaces as types and an instance of any class that implements the specific interface as the argument. For example, if we use IAlien as the required type for an argument, we can pass an instance of any class that implements IAlien as the argument.

However, you must take into account some limitations of all the interfaces compared with classes. Interfaces...