どこでいつ使用するのか知りたいですか?
例えば、
interface IDemo
{
// Function prototype
public void Show();
}
// First class using the interface
class MyClass1 : IDemo
{
public void show()
{
// Function body comes here
Response.Write("I'm in MyClass");
}
}
// Second class using the interface
class MyClass2 : IDemo
{
public void show()
{
// Function body comes here
Response.Write("I'm in MyClass2");
Response.Write("So, what?");
}
これら 2 つのクラスは、本体が異なる同じ関数名を持ちます。これは、インターフェイスがなくても実現できます。では、なぜいつどこでそれを使用するためにインターフェイスが必要なのでしょうか?