1

Well till now I knew we implement interfaces , but today some body (you know who , i guess)) told me that If I write a interface then we implement it in class , but if it is a system Interface , Let's say INotifyPropertyChanged , the we call it Class A inherits Interface INotifyPropertyChanged.

Though I feel right , I am not sure and unsure how to explain it to him.

I need to specify in my Design doucment . So wondering what shall I mention, Inherit or Implemet.

  • Part of the confusion stems from c++ lacking `interface` that is distinct from `class`. Users of Java will be able to point out their differences. – rwong Oct 14 '10 at 07:56
  • This is really a C# question, but as other have said you implement an interface. This is done by inheriting from it. – Daniel Lidström Oct 14 '10 at 08:06
  • helpful question I found is here http://stackoverflow.com/q/8531292/1055241 – gprathour Jan 27 '12 at 07:21

4 Answers4

5

We inherit it to implement it. What's the problem?

Yakov Galka
  • 70,775
  • 16
  • 139
  • 220
1

1-Interface is implemented by a class whether is it a normal interface or system interface.

2- One Interface can inherit another interface.

TalentTuner
  • 17,262
  • 5
  • 38
  • 63
1

Speaking language-independant you would say "implementing an interface". The symbol in UML names it the same (there is a special implementing-arrow which is used for interfaces instead of the inheriting-arrow)
Anybody understanding UML would understand what you're meaning.

In C++ you have to consider that there aren't interfaces as they exist in other languages. A interface is a pure virtual class. So classes which "use" this interface are strictly speaking inheriting from a pure virtual class. If you're saying "MyClass inherits the pure virtual class IClass" someone C++-related would understand that you mean interface I think. He also would understand if you say "MyClass is implementing IClass" and in background think of a pure virtual class.

MOnsDaR
  • 8,401
  • 8
  • 49
  • 70
0

If Class A provides the method bodies (that is, code) for the methods that are declared in the interface, then Class A is implementing the interface.

In C++, because of the lack of distinction between interface and class, the source code syntax for inheriting from a class and implementing an interface is the same. Hence the confusion.

rwong
  • 6,062
  • 1
  • 23
  • 51