Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step2 리펙터링(메뉴) 입니다. #103

Open
wants to merge 7 commits into
base: baekseungyeol
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kitchenpos.products.tobe.domain;
package kitchenpos.products.tobe.menu.domain;

import kitchenpos.products.tobe.support.Value;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kitchenpos.products.tobe.domain;
package kitchenpos.products.tobe.menu.domain;

import kitchenpos.menus.domain.MenuGroup;

Expand Down Expand Up @@ -44,7 +44,7 @@ public class Menu {
protected Menu() {
}

public Menu(final DisplayedName name, final BigDecimal price, final List<MenuProduct> menuProducts) {
private Menu(final DisplayedName name, final BigDecimal price, final List<MenuProduct> menuProducts) {
this(null, name, new MenuPrice(price), menuProducts);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kitchenpos.products.tobe.domain;
package kitchenpos.products.tobe.menu.domain;

import kitchenpos.products.tobe.support.Value;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kitchenpos.products.tobe.domain;
package kitchenpos.products.tobe.menu.domain;

import kitchenpos.products.domain.Product;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package kitchenpos.products.tobe.domain;
package kitchenpos.products.tobe.menu.domain;

import kitchenpos.products.tobe.support.Value;

import javax.persistence.*;
import java.util.List;

@Embeddable
public class MenuProducts {
public class MenuProducts extends Value<MenuProducts> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

menu 도메인이 별도의 서버로 분리가 된다면 Value 에 대한 의존성은 어떨까요?

중복을 제거하기 위한 상속은 좋으나 BoundedContext 단위로 도메인을 생각해보면 좋을 것 같아요



@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kitchenpos.products.tobe.domain;
package kitchenpos.products.tobe.menu.domain;

interface Profanities {
boolean contains(String text);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package kitchenpos.products.tobe.domain;
package kitchenpos.products.tobe.product.domain;


import kitchenpos.products.infra.PurgomalumClient;

import javax.persistence.*;
import javax.validation.constraints.Email;
import java.math.BigDecimal;
import java.util.UUID;

Expand Down Expand Up @@ -39,4 +38,6 @@ public BigDecimal getPrice() {
public void changePrice(BigDecimal price) {
this.price = new ProductPrice(price);
}


}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package kitchenpos.products.tobe.domain;
package kitchenpos.products.tobe.product.domain;

import kitchenpos.products.infra.PurgomalumClient;
import kitchenpos.products.tobe.support.Value;
import org.apache.logging.log4j.util.Strings;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import java.util.Objects;

@Embeddable
public class ProductName {
public class ProductName extends Value<ProductName> {

private static final String PRODUCT_NAME_EMPTY_MESSAGE = "상품의 이름은 비어있을 수 없습니다.";
private static final String PRODUCT_NAME_PROFANITY_MESSAGE = "상품의 이름은 비속어가 포함될 수 없습니다.";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package kitchenpos.products.tobe.domain;
package kitchenpos.products.tobe.product.domain;

import kitchenpos.products.tobe.support.Value;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import java.math.BigDecimal;
import java.util.Objects;

@Embeddable
public class ProductPrice {
public class ProductPrice extends Value<ProductPrice> {

private static final String PRODUCT_PRICE_EMPTY_MESSAGE = "상품의 가격은 비어있을 수 없습니다.";
private static final String PRODUCT_PRICE_NEGATIVE_MESSAGE = "상품의 가격은 음수일 수 없습니다.";
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/kitchenpos/products/tobe/support/Value.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package kitchenpos.products.tobe.support;

import java.util.Arrays;
import java.util.Objects;

public abstract class Value<T extends Value<T>> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추상화를 잘 표현해주셨어요 👍
하지만 util 및 support 와 같이 여러 객체에서 사용을 한다면 어떤 단점이 있을까요?

OOP 와 DDD 의 차이를 한번 생각해 보아요 :)


public boolean equals(final Object o) {
if(this == o) return true;
if(o == null || getClass() != o.getClass()) return false;

return Arrays.stream(getClass().getDeclaredFields())
.allMatch(field -> {
field.setAccessible(true);
try {
return Objects.equals(field.get(this),field.get(o));
} catch (IllegalAccessException e) {
e.printStackTrace();
return false;
}
});
}

public int hashCode() {
return Objects.hash(
Arrays.stream(getClass().getDeclaredFields())
.map(field -> {
field.setAccessible(true);
try {
return field.get(this);
} catch (IllegalAccessException e) {
e.printStackTrace();
return null;
}
}).toArray()
);

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package kitchenpos.products.tobe.domain;

import kitchenpos.products.tobe.menu.domain.DisplayedName;
import kitchenpos.products.tobe.domain.Menu.Profanities;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package kitchenpos.products.tobe.domain;

import kitchenpos.products.tobe.domain.Menu.Profanities;

import java.util.Arrays;
import java.util.List;

Expand All @@ -11,8 +13,6 @@ public boolean contains(final String text) {
return values.stream()
.anyMatch(text::contains);
}

;
}


Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kitchenpos.products.tobe.domain;

import kitchenpos.products.tobe.menu.domain.MenuPrice;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kitchenpos.products.tobe.domain;

import kitchenpos.products.tobe.menu.domain.*;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import kitchenpos.products.application.FakePurgomalumClient;
import kitchenpos.products.infra.PurgomalumClient;
import kitchenpos.products.tobe.product.domain.ProductName;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package kitchenpos.products.tobe.domain;

import kitchenpos.products.tobe.product.domain.ProductPrice;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.NullAndEmptySource;
import org.junit.jupiter.params.provider.NullSource;
import org.junit.jupiter.params.provider.ValueSource;

import java.math.BigDecimal;

import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
import static org.junit.jupiter.api.Assertions.*;

class ProductPriceTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import kitchenpos.products.application.FakePurgomalumClient;
import kitchenpos.products.infra.PurgomalumClient;
import kitchenpos.products.tobe.product.domain.Product;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;

import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
import static org.junit.jupiter.api.Assertions.*;

class ProductTest {

Expand Down