질문&답변
11. Null is not an error의 예제인 top 함수는 커맨드인가요 쿼리인가요??
public int pop() { if(isEmpty()) throw new Underflow(); return elements[--size]; } public Integer top() { if(isEmpty()) throw new Empty(); return elements[size - 1]; } pop은 내부 상태를 변경(size를 감소시킴)시키고, 값을 반환해서 command이면서 query여서 CQS를 위반하고 있고, top은 쿼리입니다. https://github.com/msbaek/stack-example/blob/master/src/main/java/BoundedStack.java CQS를 준수하는 것은 가독성, 코드 읽는 사람의 기대에 부합하기게 필요한 요건입니다. CQS를 최대한 준수해야겠지만 간간이 CQS를 준수할 수 없는 상황이 발생합니다.
- 좋아요수
- 0
- 댓글수
- 2
- 조회수
- 141





