You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
코드를 보면 memberServiceImpl은 인터페이스 MemberRepository를 의존하는 것처럼 보이지만 실제 인스턴스도 같이 참조하는 것이다.
이는 추상화에 의존해야 한다는 DIP 원칙을 위반한 것으로 위 코드는 추상된 것과 구체적인 것 두개에 모두 의존하는 코드이다.
DIP 원칙 위반으로 연쇄적으로 OCP도 위반하게 된다. 그 이유는 만약 요구사항의 변경으로 repository 구현체가 다른 것으로 변경되면 코드를 수정해주어야 하기 때문이다. 만약 MemoryRepsoitory에서 다른 구현체로 바뀌게 되면 코드를 수정해 주어야 한다.
클래스의 역할을 보면 비즈니스 로직을 실행하는 역할과 memberRepository 인스턴스를 생성하는 역할을 담당해 하나의 클래스에서 2개의 책임을 갖게 된것이다. 이는 SRP 원칙에 어긋나는 코드 설계이다.
DIP, OCP, SRP 원칙을 지키기 위해 역할을 기준으로 클래스를 분리하자. 비즈니스 로직에 집중하는 클래스와 인스턴스를 생성하는 역할을 나누어 클래스를 설계하면 객체지향 설계 원칙을 지키며 코드를 구현할 수 있다.
The text was updated successfully, but these errors were encountered:
코드를 보면 memberServiceImpl은 인터페이스 MemberRepository를 의존하는 것처럼 보이지만 실제 인스턴스도 같이 참조하는 것이다.
이는 추상화에 의존해야 한다는 DIP 원칙을 위반한 것으로 위 코드는 추상된 것과 구체적인 것 두개에 모두 의존하는 코드이다.
DIP 원칙 위반으로 연쇄적으로 OCP도 위반하게 된다. 그 이유는 만약 요구사항의 변경으로 repository 구현체가 다른 것으로 변경되면 코드를 수정해주어야 하기 때문이다. 만약 MemoryRepsoitory에서 다른 구현체로 바뀌게 되면 코드를 수정해 주어야 한다.
클래스의 역할을 보면 비즈니스 로직을 실행하는 역할과 memberRepository 인스턴스를 생성하는 역할을 담당해 하나의 클래스에서 2개의 책임을 갖게 된것이다. 이는 SRP 원칙에 어긋나는 코드 설계이다.
DIP, OCP, SRP 원칙을 지키기 위해 역할을 기준으로 클래스를 분리하자. 비즈니스 로직에 집중하는 클래스와 인스턴스를 생성하는 역할을 나누어 클래스를 설계하면 객체지향 설계 원칙을 지키며 코드를 구현할 수 있다.
The text was updated successfully, but these errors were encountered: