Skip to content

Instantly share code, notes, and snippets.

@slimbo
Created October 31, 2012 02:29
Show Gist options
  • Select an option

  • Save slimbo/3984461 to your computer and use it in GitHub Desktop.

Select an option

Save slimbo/3984461 to your computer and use it in GitHub Desktop.
Hit the Bits! - CFInterface - C# Version
interface IAccount
{
decimal GetBalance();
}
class CheckingAccount : IAccount
{
public decimal GetBalance()
{
return 0;
}
public void WriteCheck(decimal amount, string recipient)
{
Console.WriteLine("Writing a check to " + recipient + " in the amount of " + amount);
}
}
class SavingsAccount : IAccount
{
public decimal GetBalance()
{
return 0;
}
}
class Program
{
static void Main(string[] args)
{
ExerciseAccount(new CheckingAccount());
ExerciseAccount(new SavingsAccount());
}
static void ExerciseAccount(IAccount account)
{
Console.WriteLine("Balance of this account is " + account.GetBalance());
account.WriteCheck(20.0m, "Mr. Smith"); // <------- Compiler Error!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment