Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of...

25
Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven Design: Tacking Complexity in the Heart of Software (Ch. 16). Addison-Wesley Longman Publishing Co., Inc.

Transcript of Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of...

Page 1: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

Domain-Driven Design:Large-Scale Structure*To-ju HuangComputer Science Department

University of California, San Diego

April 23, 2010

1*Evans 2003 Domain-Driven Design: Tacking Complexity in the Heart of Software (Ch. 16). Addison-Wesley Longman Publishing Co., Inc.

Page 2: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

Outline

• Motivating Example – Online Bookstore• Background

• Domain-Driven Design• Role of Large-Scale Structure

• Large-Scale Structure• Responsibility Layer• Knowledge Level• Pluggable Component Framework

• Conclusion

Page 3: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

Motivating Example - Online Bookstore

• Requirements• Customers can place orders online• Customers can pay orders online (credit cards or PayPal)• Customers can access order, shipping, payment information• Warehouse staff can prepare and ship orders• Warehouse staff can contact distributors to restock

• Assumptions (some will change later)• Single warehouse and single seller

(i.e. the owner company itself)• No physical store (only online-purchase)

Page 4: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

Motivating Example - Online Bookstore

order

orderline book

shipment payment

bookcatalog

stock distributor

credit cardtransaction

PayPaltransaction

courier

customer

warehouse

* *

1

1

1

*

*1

1..*

11

Page 5: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

Motivating Example - Online Bookstore

• Modeling Challenges• We may miss the big picture when the model grows big

• Relations among entities can change on the fly; we need flexibility while obeying high-level domain restrictions

• The same high-level abstraction recurs among projects which do not work closely together; the similarity ends right here and prevents further reuse

Page 6: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

Outline

• Motivating Example – Online Bookstore• Background

• Domain-Driven Design• Role of Large-Scale Structure

• Large-Scale Structure• Responsibility Layer• Knowledge Level• Pluggable Component Framework

• Conclusion

Page 7: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

Domain-Driven Design

• What Domain-Driven Design is about?• Shared models serve both design and implementation teams• Communication via unified domain languages, whose

vocabulary is used to through the models• Efficient communication helps stakeholders gain and accumulate

insights, which in turn enter the unification domain language; this forms a positive feedback loop

• Relation to Model-Driven Engineering initiatives (e.g. MDA)• Both are domain engineering approaches• Both advocate the central role of models in software

development• DDD focuses more on modeling practices;

MDE initiatives are more about the development processes

7

Page 8: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

Role of Large-Scale Structure

• Help stakeholders to grasp the high-level of the model; everybody can identify and locate his responsibility easily

• Efficient communication is assured: different teams can understand their roles and relations to the others

• Prevents teams from diverging to the point that the whole project breaks into remotely related pieces

8

Page 9: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

Outline

• Motivating Example – Online Bookstore• Background

• Domain-Driven Design• Role of Large-Scale Structure

• Large-Scale Structure• Responsibility Layer• Knowledge Level• Pluggable Component Framework

• Conclusion

Page 10: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

Responsibility Layer

• Layers help us track dependencies more easily, but we need more guidance on making layers

10

why 3 layers?

could this be on layers lower?

why in the same layer?

Page 11: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

Responsibility Layer

• Some meaningful partitions may manifest themselves, by the responsibilities assumed by a group of entities

11

order

orderline book

shipment payment

bookcatalog

stock distributor

credit cardtransaction

PayPaltransaction

courier

customer

warehouse

* *

1

1

1

*

*1

1..*

1

AND, beware of the dependencies among layers

operation

capability

Page 12: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

Responsibility Layer

• Lower layers should not know upper layers

12

order

orderline book

shipment payment

bookcatalog

stock distributor

credit cardtransaction

PayPaltransaction

courier

customer

warehouse

* *

1

1

1

*

*1

1..*

1

operation

capability

product

Page 13: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

Responsibility Layer

• We can have more layers according to responsibilities

13

order

orderline book

shipment payment

bookcatalog

stock

distributorcredit cardtransaction

PayPaltransaction

courier

customer

warehouse

* *

1

1

1

*

*1

1..*

1

product

capability

operation

policy

decision

promotionpolicy

discount policy

pricing

discount/promotionenabler

sales report,business analysis

Page 14: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

Outline

• Motivating Example – Online Bookstore• Background

• Domain-Driven Design• Role of Large-Scale Structure

• Large-Scale Structure• Responsibility Layer• Knowledge Level• Pluggable Component Framework

• Conclusion

Page 15: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

Knowledge Level

• Now, the online bookstore allows 3rd-party booksellers

15

book

stock distributor

warehouse

1..*

1product

book

stock distributor

warehouse

1..*

1product

individualwarehouse

owned warehouse

self-suppliedstock

regularstock

manufacturinginfo

Page 16: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

Knowledge Level

• However, the company decided that some individual sellers could be bought in, so owned warehouse can be associated both kind of stock …

16

stock

warehouse

individualwarehouse

owned warehouse

self-suppliedstock

regularstock

TOO RESTRICTED

manufacturinginfo distributor

1..*

Page 17: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

Knowledge Level

• However, the company decided that some individual sellers could be bought in, so owned warehouse can be associated both kind of stock …

17

stock distributor

warehouse

1..*

individualwarehouse

owned warehouse

self-suppliedstock

regularstock

stock

distributor

warehouse

1..*

individualwarehouse

owned warehouse

self-suppliedstock

regularstock

manufacturinginfo

manufacturinginfo

Page 18: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

Knowledge Level

• But, this is a weird that individual seller can have regular stock or owned-warehouse have manufacturing info

18

TOO LOOSE

stock

distributor

warehouse

1..*

individualwarehouse

owned warehouse

self-suppliedstock

regularstock

manufacturinginfo

Page 19: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

Knowledge Level

• But, this is a weird that individual seller can have regular stock

19

stock

distributor

warehouse

1..*

individualwarehouse

owned warehouse

self-suppliedstock

regularstock

manufacturinginfo

Page 20: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

Knowledge Level

• We introduce the warehouse type which indirectly associate stock, distributor, manufacturing info to warehouse while can only be modified by certain entities

20

stock

distributor

warehouse

1..*

individualwarehouse

owned warehouse

self-suppliedstock

regularstock

manufacturinginfo

warehouse

manufacturinginfo

distributor

warehousetype

regularstock

self-suppliedstock

1

stock

Page 21: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

• We introduce the warehouse type which indirectly associate stock, distributor, manufacturing info to warehouse while can only be modified by certain entities

21warehouse

manufacturinginfo

distributor

warehousetype

regularstock

self-suppliedstock

1

stock

Knowledge Level

Operation Level

Page 22: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

Outline

• Motivating Example – Online Bookstore• Background

• Domain-Driven Design• Role of Large-Scale Structure

• Large-Scale Structure• Responsibility Layer• Knowledge Level• Pluggable Component Framework

• Conclusion

Page 23: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

Pluggable Component Framework

• Entities can be substituted by compatible plugins• However, agreed-upon standards are required…

23

order

orderline<<interface >>

product

shipment<<interface >>

payment

<<interface >>

catalog

stock<<interface >>

distributor

credit cardtransaction

PayPaltransaction

<<interface >>

courier

customer

<<interface >>

warehouse

* *

1

1

1

*

*1

1..*

1

Page 24: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

Conclusion

• Large-scale structure helps stakeholders to understand their roles, improve communication, and keep project coherent

• Dependencies can be turned into responsibility layers with clear meanings

• Knowledge level allows flexible relations among entities while keeping the model consistent with the business logic

• Pluggable component framework, if feasible standards employed, can make high-level architecture fully utilized

24

Page 25: Domain-Driven Design: Large-Scale Structure* To-ju Huang Computer Science Department University of California, San Diego April 23, 2010 1 *Evans 2003 Domain-Driven.

Thank You

25