/// Notice how similar it is to the first example?
/// The code is only changed in one place
/// and the change is propogated everywhere else
class Program
{
static void Main(string[] args)
{
Account freddie = new Account(5000000);
// freddie buys a grand piano
freddie.balance = freddie.balance - 500000m;
// freddie buys a leather jacket
freddie.balance = freddie.balance - 5000m;
// freddie buys a beer in Singapore
freddie.balance = freddie.balance - 20;
}
}
public class Account
{
private decimal _balance;
public decimal balance
{
get
{
_balance = _balance * 1.25m;
return _balance;
}
set { _balance = value; }
}
public Account(decimal balance)
{
this._balance = balance;
}
}
Created
April 13, 2017 00:03
-
-
Save benkoshy/ede9d43c5d35f4620c542a5ee18c56f0 to your computer and use it in GitHub Desktop.
Depend on Behaviour not data: Here we make the change only once, but it is reflected everywhere. It's much easier to maintain.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment