Skip to content

Instantly share code, notes, and snippets.

@redutan
Last active June 7, 2018 07:12
Show Gist options
  • Save redutan/b85b54bdf95d2094dbd462632859865d to your computer and use it in GitHub Desktop.
Save redutan/b85b54bdf95d2094dbd462632859865d to your computer and use it in GitHub Desktop.
Entity Arguments
interface ProductDesc {
String getTitle();
long getPrice();
String getContent();
boolean isDiscountable();
}
@Entity
@Getter
@EqualsAndHashCode
@ToString
@NoArgsConstructor(access = PACKAGE)
class Product implements ProductDesc {
@Id
@GeneratedValue
private Long id;
private String title;
private long price;
private String content;
private boolean discountable;
public void update(ProductDesc param) {
if (param.getPrice() < 0) {
throw new IllegalArgumentException("price must greater than 0");
}
this.title = param.getTitle();
this.price = param.getPrice();
this.content = param.getContent();
this.discountable = param.isDiscountable();
}
}
@Value
class ProductUpdate {
private String title;
private long price;
private String content;
private boolean discountable;
public ProductDesc(String title, long price, String content, boolean discountable) {
if (param.getPrice() < 0) {
throw new IllegalArgumentException("price must greater than 0");
}
this.title = title;
this.price = price;
this.content = content;
this.discountable = discountable;
}
}
@Entity
@Getter
@EqualsAndHashCode
@ToString
@NoArgsConstructor(access = PACKAGE)
class Product {
@Id
@GeneratedValue
private Long id;
private String title;
private long price;
private String content;
private boolean discountable;
public void update(ProductUpdate param) {
this.title = param.getTitle();
this.price = param.getPrice();
this.content = param.getContent();
this.discountable = param.isDiscountable();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment