Created
May 22, 2019 06:29
-
-
Save aswhitehouse/7faa796678e8b6ce8b1dafd88565e979 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//What I'm trying to work out stylistically is that is it a code smell to do something like, calling into an object heirachy | |
//Like this => this.setFirstName(order.getCustomer().getFirstName()); | |
//The "ORDER" creates a "CUSTOMER", the "CUSTOMER" has properties that the order calls down into | |
public class Usage { | |
public OrderResponse createOrder(CustomerOrder order) { | |
OrderProcessor processor = new OrderProcessor(); | |
CustomerOrderPayload customerOrderPayload = new CustomerOrderPayload() {{ | |
this.setFirstName(order.getCustomer().getFirstName()); | |
this.setLastName(order.getCustomer().getLastName()); | |
}}; | |
Order order = new Order() {{ | |
this.setProductList(createOrderList(customerOrderPayload, order)); | |
}}; | |
return processor.processOrder(customerOrderPayload, order); | |
} | |
} | |
public class CustomerOrderPayload { | |
private Customer customer; | |
public void setCustomer(Customer customer) { | |
this.customer = customer; | |
} | |
public Customer getCustomer() { | |
return this.customer; | |
} | |
} | |
public class Customer { | |
private String firstName; | |
private String lastName; | |
public void setFirstName(String firstName) { | |
this.firstName = firstName; | |
} | |
public void setLastName(String lastName) { | |
this.lastName = lastName; | |
} | |
public String getFirstName() { | |
return this.firstName; | |
} | |
public String getLastName() { | |
return this.lastName; | |
} | |
} |
How about this?
public class Usage {
public OrderResponse createOrder(CustomerOrder order) {
OrderProcessor processor = new OrderProcessor();
Customer customer = new Customer();
customer
.setFirstName("Steve")
.setLastName("Smith)
.build();
CustomerOrderPayload customerOrderPayload = new CustomerOrderPayload();
customerOrderPayload
.setCustomer(customer)
.build();
ProductList productList = new ProductList();
productList.setItem("item")
.setItem("item)
.build();
Order order = new Order();
order.setProductList(productList);
.build();
CustomerOrderPayload customerOrderPayload = new CustomerOrderPayload(customerOrderPayload);
return processor.processOrder(customerOrderPayload, order);
}
}
From your original comment you mean.
Customer customer = new Customer();
customer.setFirstName("Steve");
CustomerOrderPayload customerOrderPayload = new CustomerOrderPayload()
{{
this.setCustomer(customer);
}};
?
From your original comment you mean.
Customer customer = new Customer();
customer.setFirstName("Steve");CustomerOrderPayload customerOrderPayload = new CustomerOrderPayload()
{{
this.setCustomer(customer);
}};?
Yup
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 10:
Just set the customer and then in the
setCustomer()
method set the properties...