Is interface inheritance possible? Why is it required? why wouldn't I implement 2 interfaces instead of doing an interface inheritance?
Ans: Suppose there is a class that I want to function as a Bank Account. Now there are 5 classes that are 5 different types of Bank Accounts which have a function CalculateInterest(). I would define an interface called IBankAccount Interface and implement this interface in my 5 classes to make them BankAccounts. Now I want one bank account to do something special. It should contain all the existing functions of a normal bank account and should specialize in something.
So I would create a new Interface say, ISpecialBankAccount and inherit it from IBankAccount. Now in my special class I would implement ISpecialBankAccount.
Now I can omit the inheritance of interfaces and implement both these interfaces. And from the code perspective it would be the same thing. But when I am breaking the rules of OO. From a design perspective it would make more logical sense. because ISpecialBankAccount would contain all the functions of the IBankAccount interface and it would add special functionality to it.
So Implementing ISpecialBankAccount in our special class would keep the existing bank account as they are and would also have special features of the ISpecialBankAccount.
Wednesday, April 18, 2007
Interface Inheritance
Posted by Don at 10:57 PM
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment