/// <summary> /// Rule 3) Objects must be initialized to a valid state. Not doing so is a compile-time error. /// </summary> public void TestObjectsMustBeInitializedToAValidState() { // create a customer var cust = new Customer(); // what is the expected output? Console.WriteLine(cust.Address.Country); }
/// <summary> /// Rule 4) Once created, objects and collections must be immutable (by default) /// </summary> public void TestImmutability2() { // create a customer var cust = new Customer(99, "J Smith"); // add it to a set var processedCustomers = new HashSet<Customer>(); processedCustomers.Add(cust); // process it and return the changes var changedCustomer = this.ProcessCustomer(cust); // true or false? processedCustomers.Contains(cust); }
/// <summary> /// Rule 2) Comparing objects of different types is a compile-time error. /// </summary> public void TestEqualityBetweenCustomerAndOrder() { var cust = new Customer(99, "J Smith"); var order = new Customer(99, "J Smith"); var areEqual = cust.Equals(order); }
/// <summary> /// Rule 1) Objects with the same values should be equal by default. /// </summary> public void TestEqualityBetweenCustomers() { var cust1 = new Customer(99, "J Smith"); var cust2 = new Customer(99, "J Smith"); var areEqual = (cust1 == cust2); }
private Customer ProcessCustomer(Customer cust) { return new Customer(cust.Id, "new name"); }