Hi All
I'm currently working through Professional C# 2008 book and I'm busy with the Derived interfaces part. I'm a programer, but I think my OO skills are a little lacking.
Anyway, working through the example in the book. I declared the following interface
Code:
public interface IBankAccount
{
void PayIn(decimal amout);
bool Withdraw(decimal amount);
decimal Balance
{
get;
}
}
Then I declared a derived interface from the previous interface
Code:
public interface ITransferBankAccount : IBankAccount
{
bool TransferTo(IBankAccount destination, decimal amount);
}
I then wrote two classes that uses these interfaces
Code:
public class SaverAccount : IBankAccount
{
// code here
}
public class CurrentAccount : ITransferBankAccount
{
// code here
}
Then in my main, it looks like this
Code:
class MainEntryPoint
{
static void Main()
{
IBankAccount venusAccount = new SaverAccount();
IBankAccount jupiterAccount = new CurrentAccount();
venusAccount.PayIn(200);
jupiterAccount.PayIn(500);
Console.WriteLine(venusAccount.ToString());
Console.WriteLine(jupiterAccount.ToString());
Console.ReadLine();
}
}
Now some of you will probably already have noticed that I've declared jupiterAccount as a IBankAccount type, rather than a
ITransferBankAccount type, yet I've instanced it as a CurrentAccount object.
This isn't how the code in the book goes, but it was a mistake made by me, yet it compiles and works. When I explored this, it looks like I had access to all the methods/types defined in the IBankAccount interface, but even though the TransferTo() function is declared in the CurrentAccount class, I don't have access to it and calling it gives a compile error.
Is this intended?
Syn