8 abstract classes and interfaces Presentation Transcript
Abstract classes & Interfaces Programming in C# firstname.lastname@example.org
Abstract Classes referred to as an incomplete base class cannot be instantiated, can only be sub-classed.
Implementation The subclass inheriting the abstract class has to override and implement the abstract methods https://gist.github.com/2373593
Purpose A subclass in C# cannot inherit two or more base class.
Interfaces contains only abstract members cannot implement any methods cannot be instantiated by default, all members have public as the access modifier cannot contain constants, data fields, constructors, destructor and static members
Interface Inheritance An interface can inherit multiple interfaces but cannot implement them. https://gist.github.com/2374963
What difference between abstract classes & Interfaces?
Short Interface: contract only, no implementation, no instantiation Abstract class: contract, some implementation, no instantiation Interface specifying what the object can do Abstract specify what an object is
Similarities cannot be instantiated are implemented by the inheriting subclass can inherit multiple interfaces
Multiple version of component => Abstract classfunctionality will be useful across a wide range of disparate objects => Interfacessmall, concise function bits of functionality => Interfacescommon, implemented functionality among all implementations ofyour component => Abstract class