1. first situation:
one class implement one interface
and all the interface implementation is implicit
public interface IBankAccount
{
void PayIn(decimal amount);
bool Withdraw(decimal amount);
decimal Balance{get;}
}
public class SaverAccount : IBankAccount
{
//类SaverAccount独有的
public void PayIn2()
{
}
//接口IBankAccount可以访问的
public void PayIn(decimal amount)
{
}
//接口IBankAccount可以访问的
public bool Withdraw(decimal amount)
{
return false;
}
//接口IBankAccount可以访问的
public decimal Balance
{
get
{
return 1;
}
}
}
when use IBankAccount
IBankAccount ba = new SaverAccount();
ba.PayIn(1);
SaverAccount sa = new SaverAccount();
sa.PayIn(2);
sa.PayIn2();//接口不能调用
2. the second situation
//the tiny difference is PayIn is explicit implementation
//接口IBankAccount可以访问的
public void IBankAccount.PayIn(decimal amount)
{
}
//此时PayIn不可调用
sa.PayIn(2);
3. one class implement multiple interface
each interface can only invoke the member and function that is assigned by itself.
if the class explicit one interface's function, the instance of this class couldn't invoke the explicit interface fuction