빈약한 도메인 모델
빈약한 도메인 모델(anemic domain model)은 도메인 객체들에 비즈니스 로직(확인, 계산, 비즈니스 규칙 등)이 거의 없거나 아예 없는 소프트웨어 도메인 모델의 이용이다.
개요 편집
이 패턴은 해당 기법을 안티패턴으로 간주한 마틴 파울러에 의해 처음 기술되었다.[1]
- 안티패턴의 근본적인 공포는 객체 지향 디자인의 기초적인 개념과 반대된다는 점이다. (즉, 데이터와 과정을 한 데 병합하는 것) 빈약한 도메인 모델은 단지 절차적 스타일의 디자인이다... 수많은 사람들은 빈약한 객체들이 실제 객체들로 생각하므로 객체 지향 설계의 요점을 완전히 놓치게 된다.
예시 편집
빈약함
class Box
{
public int Height { get; set; }
public int Width { get; set; }
}
빈약하지 않음
class Box
{
public int Height { get; private set; }
public int Width { get; private set; }
public Box(int height, int width)
{
if (height <= 0) {
throw new ArgumentOutOfRangeException(nameof(height));
}
if (width <= 0) {
throw new ArgumentOutOfRangeException(nameof(width));
}
Height = height;
Width = width;
}
public int Area()
{
return Height * Width;
}
}