...
Code Block | ||
---|---|---|
| ||
public class Customer {
@Value @Accessors(fluent = true)
public class PlaceOrderParameters {
Product product;
int quantity;
}
public Customer placeOrder(Product p, int quantity) { ... }
public boolean hidePlaceOrder() { ... }
public String disablePlaceOrder() { ... }
public String disable1PlaceOrder(PlaceOrderParameters params) { ... }
public Collection<Product> choices0PlaceOrder() { ... }
public Product default0PlaceOrder() { ... }
public int default1PlaceOrder() { ... }
public String validate1PlaceOrder(PlaceOrderParameters params) { ... }
public String validatePlaceOrder(PlaceOrderParameters params) { ... }
} |
The \@Value \@Accessors(fluent=true) allows us to use a syntax that is very similar to Java 14 records.
Note that there is some duplication here: the list of the parameter types appears both in the "placeOrder(...)" method, as well as in the PlacerOrdersParameters class.
The above would also be supported with mixinsThere are two variants here. The first just uses the Parameters object for the supporting methods:
public class Customer { ... }
@Action // or @Mixin(method="act") and a bunch of other annotations
public class Customer_placeOrder() { // infer action name from the mixin class name
private final Customer target; // constructor omitted
public Customer act(Product p, int quantity) { ... }
public boolean hideAct() { ... }
public String disableAct() { ... }
public String disable1Act(Product p) { ... }
public Collection<Product> choices0Act() { ... }
public Product default0Act() { ... }
public int default1Act() { ...}
public String validate1Act(int quantity) { ... }
public String validateAct(Product p, int quantity) { ... }
}
...