Last active
December 27, 2016 16:11
-
-
Save zharro/5dc1aff5e7d77c5b5c6aa2f85f3c5991 to your computer and use it in GitHub Desktop.
Functions composition vs temporal coupling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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