Last active
June 7, 2018 07:12
-
-
Save redutan/b85b54bdf95d2094dbd462632859865d to your computer and use it in GitHub Desktop.
Entity Arguments
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
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(); | |
} | |
} |
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
@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