Merged
Conversation
Member
Author
guswns3371
commented
Jan 22, 2023
Comment on lines
+3
to
+35
| public abstract class MenuComponent { | ||
| public void add(MenuComponent menuComponent) { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| public void remove(MenuComponent menuComponent) { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| public MenuComponent getChild(int i) { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| public String getName() { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| public String getDescription() { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| public double getPrice() { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| public boolean isVegetarian() { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| public void print() { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
| } |
Member
Author
There was a problem hiding this comment.
한 클래스(
MenuComponent)에 2가지 역할을 넣고 있다.
컴포지트 패턴은 어떤 원소가 복합객체이고 단일 객체인지 클라이언트에게 투명하게 보이게 하기 위해 SRP 디자인 원칙을 위배하였다.
만약 여러 역할을 서로 다른 인터페이스로 분리한다면, 복합/단일 객체가 각각 부적절한 메소드를 호출하는 상황이 일어나지 않게 된다. 하지만 이는 투명성을 떨어뜨리고, 복합/단일 객체를 분리해야하기 때문에 코드에서 분기처리문이 늘어나게 된다 (instanceof)
따라서 상황에 따라 투명성과 안정성 사이에서 적절한 균형을 찾아야 한다.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


No description provided.