Difference between revisions of "OOP Class8"
Line 7: | Line 7: | ||
An interface is a class that lacks implementation. The only thing it contains are definitions of events, indexers, methods and/or properties. The reason interfaces only provide definitions is because they are inherited by classes and structs, which must provide an implementation for each interface member defined. Since classes in c# can only be derived from one other class ( in c++ it is possible to derive from many) interfaces are used for multiple inheritance. Like abstract classes you cannot create an instance of an interface on derive from it. | An interface is a class that lacks implementation. The only thing it contains are definitions of events, indexers, methods and/or properties. The reason interfaces only provide definitions is because they are inherited by classes and structs, which must provide an implementation for each interface member defined. Since classes in c# can only be derived from one other class ( in c++ it is possible to derive from many) interfaces are used for multiple inheritance. Like abstract classes you cannot create an instance of an interface on derive from it. | ||
− | + | You cannot create an instance of an interface. | |
− | + | ||
+ | Interfaces cannot contain any implementation. | ||
+ | |||
+ | Interfaces are basically a contract between classes. When a class implements an interface it is promising to implement the propery and method signature of that interface. This helps with abstraction and encurages polymorphism. | ||
+ | |||
Phone interface example | Phone interface example | ||
− | phoneIFace.cs -source | + | |
+ | [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class8/phoneIFace.cs phoneIFace.cs] -source | ||
+ | |||
Multiple interface inheritance - inherits IPhone, Cell, POTS | Multiple interface inheritance - inherits IPhone, Cell, POTS | ||
− | / | + | [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class8/phoneIFacePOTS.cs phoneIFacePOTS.cs] -source |
[http://ia300218.us.archive.org/2/items/arsdigitac04n04/Lecture_04.html ArsDigita University Course 04: Object-oriented Program Design and Software Engineering - Lecture Notes 4] | [http://ia300218.us.archive.org/2/items/arsdigitac04n04/Lecture_04.html ArsDigita University Course 04: Object-oriented Program Design and Software Engineering - Lecture Notes 4] | ||
− | [http:// | + | [http://ia300218.us.archive.org/2/items/arsdigitac04n05/Lecture_05.html ArsDigita University Course 04: Object-oriented Program Design and Software Engineering - Lecture Notes 5] |
Revision as of 22:01, 12 March 2006
Interfaces
Interfaces - implements or derives from
An interface is a class that lacks implementation. The only thing it contains are definitions of events, indexers, methods and/or properties. The reason interfaces only provide definitions is because they are inherited by classes and structs, which must provide an implementation for each interface member defined. Since classes in c# can only be derived from one other class ( in c++ it is possible to derive from many) interfaces are used for multiple inheritance. Like abstract classes you cannot create an instance of an interface on derive from it.
You cannot create an instance of an interface.
Interfaces cannot contain any implementation.
Interfaces are basically a contract between classes. When a class implements an interface it is promising to implement the propery and method signature of that interface. This helps with abstraction and encurages polymorphism.
Phone interface example
phoneIFace.cs -source
Multiple interface inheritance - inherits IPhone, Cell, POTS phoneIFacePOTS.cs -source