도메인 기반 디자인 접근법에 대해 혼란스러워합니다. 그물에 근원에서 나는 당신의 Domain Objects
및 Database Objects
를 분리하는 방법다는 것을 이해했다 그러나 나는 2 사이 다름을 이해하지 않는다.장고 및 도메인 기반 디자인
예를 들어 django 튜토리얼에서 Polls 예제의 code을 사용하면 두 모델 Polls
과 Choice
이 있습니다.
이 있습니까 domain level objects
또는 database level objects
입니까?
ORM이있는 DDD가 필요합니까? 그래, 당신은 당신이 ORM 예를 들어
와 DDD 접근 방식을 사용할 필요가 좋은 상황을 제공 할 수있는 경우
,이
class Polls(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
DDD 접근 코드 나는 사람들이
를 작성 본 모델입니다class PollService(object):
def __init__(self, poll_repository):
self.poll_respository = poll_respository
def update(self, poll_id):
poll = self.poll_respository.fetch_by_id(poll_id)
poll.question += '?'
self.poll_respository.update(poll)
#assume that the following code works?
class PollRepository():
def __init__(self, db):
self.db = db
def update(self, poll):
try:
self.db.session().add(poll)
self.db.session.commit()
except Exception:
self.db.session.rollback()
올바른 방법입니까? 여기에 많은 중복 코드가 있지만 사람들은 Polls
이 도메인 수준 개체이며 데이터베이스와 직접적으로 관련이 없다고 말합니다.
DDD에는 항상 DDD- 리포지토리가 있습니까? 우리는 ORM이 있다면 왜 우리는 DDD 저장소를 필요
또 다른 방법
views.py
def update_poll(poll_id):
poll = models.Polls.objects.get(poll_id)
poll.question += '?'
poll.save()
이 방법에 문제가 있나요? 이 Django Design Philosophy 페이지에 설명
"DDD에는 항상 DDD- 리포지토리가 있습니까?"- 아니요. CQRS와 이벤트 소싱 –