15. Domain-driven design (DDD)
is an approach to software development
for complex needs
by connecting the implementation
to an evolving model.
https://en.wikipedia.org/wiki/Domain-driven_design
49. Ubiquitous Language is the term
Eric Evans uses in Domain Driven Design
for the practice of building up
a common, rigorous language
between developers and users
https://martinfowler.com/bliki/UbiquitousLanguage.html
도메인 계층 > 도메인 > 도메인 모델 > 유비쿼터스 언어
90. class Ad(Base):
impressions = relationship(AdImpressionCount)
def impression_count(self):
value = 0
for impression in self.impressions:
value += impression.value
return value
도메인 계층 > 엔티티 > 지속성 무시 > session 금지
91. class Ad(Base):
impressions = relationship(AdImpressionCount)
def impression_count(self):
value = 0
for impression in self.impressions:
value += impression.value
return value
도메인 계층 > 엔티티 > 지속성 무시 > session 금지
92. class Ad(Base):
impressions = relationship(AdImpressionCount)
def impression_count(self):
value = 0
for impression in self.impressions:
value += impression.value
return value
도메인 계층 > 엔티티 > 지속성 무시 > session 금지
93. class TestAd(Base):
def test_impression_count(self):
impressions = []
for _ in range(10):
impressions.append(AdImpressionCount())
ad = Ad(impressions=impressions)
count = ad.impression_count()
assert count == expected_count
도메인 계층 > 엔티티 > 지속성 무시 > session 금지
94. class TestAd(Base):
def test_impression_count(self):
impressions = []
for _ in range(10):
impressions.append(AdImpressionCount())
ad = Ad(impressions=impressions)
count = ad.impression_count()
assert count == expected_count
도메인 계층 > 엔티티 > 지속성 무시 > session 금지
106. 응용 계층 > 엔티티 사용
class AdService(object):
def change_period(self, ad_id, start, end):
ad = session.query(Ad).get(ad_id)
ad.start = start
ad.end = end
107. 응용 계층 > 엔티티 사용
class AdService(object):
def change_period(self, ad_id, start, end):
ad = session.query(Ad).get(ad_id)
ad.set_start(start)
ad.set_end(end)
class Ad(Base):
def set_start(self, start):
self.start = start
def set_end(self, end):
self.end = end
108. 응용 계층 > 엔티티 사용
class AdService(object):
def change_period(self, ad_id, start, end):
ad = session.query(Ad).get(ad_id)
ad.set_start(start)
ad.set_end(end)
class Ad(Base):
def set_start(self, start):
self.start = start
def set_end(self, end):
self.end = end
X
109. class AdService(object):
def change_period(self, ad_id, start, end):
ad = session.query(Ad).get(ad_id)
ad.change_period(start, end)
class Ad(Base):
def change_period(self, start, end):
self.start = start
self.end = end
응용 계층 > 엔티티 사용
110. 응용 계층 > 트랜잭션
class AdService(object):
def change_period(self, ad_id, start, end):
ad = session.query(Ad).get(ad_id)
with session.begin():
ad.change_period(start, end)
class Ad(Base):
def change_period(self, start, end):
self.start = start
self.end = end
111. class AdService(object):
def change_period(self, ad_id, start, end):
ad = session.query(Ad).get(ad_id)
with session.begin():
ad.change_period(start, end)
class Ad(Base):
def change_period(self, start, end):
self.start = start
self.end = end
응용 계층 > 트랜잭션
112. class AdService(object):
def change_period(self, ad_id, start, end):
ad = session.query(Ad).get(ad_id)
with session.begin():
ad.change_period(start, end)
class Ad(Base):
def change_period(self, start, end):
self.start = start
self.end = end
응용 계층 > 트랜잭션
113. class AdService(object):
def change_period(self, ad_id, start, end):
ad = session.query(Ad).get(ad_id)
with session.begin():
ad.change_period(start, end)
class Ad(Base):
def change_period(self, start, end):
self.start = start
self.end = end
응용 계층 > 트랜잭션