Skip to content

Instantly share code, notes, and snippets.

@lofidewanto
Created October 28, 2020 17:40
Show Gist options
  • Save lofidewanto/149df4974a6d57f4cbb6072865784b3f to your computer and use it in GitHub Desktop.
Save lofidewanto/149df4974a6d57f4cbb6072865784b3f to your computer and use it in GitHub Desktop.
IndexedDB with Java Patterns - Rich Domain Model
package com.github.lofi.client;
public class Product {
private final String id;
private final String name;
...
private Product(Builder productBuilder) {
this.id = productBuilder.id;
this.name = productBuilder.name;
...
}
public String getId() {
return id;
}
public Integer getAmount() {
return amount;
}
public Integer getPrice() {
return price;
}
public Integer getCalculatedPriceWithAmount() {
if (price == null || amount == null) {
return 0;
} else {
return price * amount;
}
}
public static class Builder {
private final String id;
private final String name;
private String type;
public Builder(String id, String name) {
this.id = id;
this.name = name;
}
public Builder setType(String type) {
this.type = type;
return this;
}
public Builder setAmount(Integer amount) {
this.amount = amount;
return this;
}
public Builder setPrice(Integer price) {
this.price = price;
return this;
}
public Product build() {
Product product = new Product(this);
return product;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment