Skip to content

Instantly share code, notes, and snippets.

@zharro
Last active December 27, 2016 16:11
Show Gist options
  • Save zharro/5dc1aff5e7d77c5b5c6aa2f85f3c5991 to your computer and use it in GitHub Desktop.
Save zharro/5dc1aff5e7d77c5b5c6aa2f85f3c5991 to your computer and use it in GitHub Desktop.
Functions composition vs temporal coupling
public class CustomerService
{
public void Process(string customerName, string addressString)
{
Address address = CreateAddress(addressString);
Customer customer = CreateCustomer(customerName, address);
SaveCustomer(customer);
}
private Address CreateAddress(string addressString)
{
return new Address(addressString);
}
private Customer CreateCustomer(string name, Address address)
{
return new Customer(name, address);
}
private void SaveCustomer(Customer customer)
{
var repository = new Repository();
repository.Save(customer);
}
}
public class CustomerServiceWithTemporalCoupling
{
private Address _address;
private Customer _customer;
public void Process(string customerName, string addressString)
{
CreateAddress(addressString);
CreateCustomer(customerName);
SaveCustomer();
}
private void CreateAddress(string addressString)
{
_address = new Address(addressString);
}
private void CreateCustomer(string name)
{
_customer = new Customer(name, _address);
}
private void SaveCustomer()
{
var repository = new Repository();
repository.Save(_customer);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment