Interfaces Inheritance

Two situations are related to both inheritance and interfaces. The first scenario is when you create a class that derives from another one that implements an interface. In such a scenario the derived class also inherits members implemented through an interface and does not need to implement the interface again. Moreover, if the base class is marked as overridable members implemented via an interface, the derived class can override such members if not private. The second scenario is a pure interface inheritance, in which an interface can inherit from another one. Continuing the previous examples, we can consider creating an IInvoice interface that inherits from IDocument providing some more specific members to represent an invoice. The following code demonstrates this:

image

As you can see, the Inherits keyword is used also for interface inheritance. In this example the new interface inherits all members’ definitions from the IDocument interface plus adds two new members, the InvoiceNumber property and the CalculateDiscount method.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.146.61