domain driven design in c#3.0
Post on 22-Nov-2014
3.303 Views
Preview:
DESCRIPTION
TRANSCRIPT
DDD with C# 3.0 features: Solar
System SimulationAndre Boonzaaijer, Pieter-Joost van de Sande
{aboonzaaijer, pjvdsande}@sogyo.nl
http://born2code.net | http://whiletrue.nl | http://sogyo.nl
Today’s agenda
• DDD – short intro• Case: Problem definition• Case: C# (2.0) solution• Case: C# 3.0 extensions• Demo
2
What is “Domain Driven”?
3
It’s not: Layering
4
Presentation Layer
Data Layer
Layering
5
Presentation Layer
Data Layer
Business logic
Layering
6
Presentation Layer
Data Layer
Business logic
Layering
7
Presentation Layer
Data Layer
Business logic
Layering
8
Presentation Layer
Data Layer
Business logic
+/- 2 years
Layering
9
Presentation Layer
Data Layer
Business logic
+/- 2 years
+/- 5 years
Layering
10
Presentation Layer
Data Layer
Business logic
+/- 2 years
+/- 5 years
?
Layering
11
Presentation Layer
Data Layer
Business logic Email
SMS
Printing
Where?
Layering
12
Presentation Layer
Data Layer
Business logic
Sunflower
13
Case…
• Build a runnable solar system simulator– 1 star in the centre– Configurable amount of planets (mass is max
1% of the star’s mass)– Laws of physics:
• F = M * a• Fg = M1*M2 / d^2
– Starting point: Random generated• Draft a domain model.
14
Gravity
15
(x,y)
force = 0;Foreach body in universe force += body.getForce(x,y);
body.move(force);
Domain
16
Wrapping the domain
17
UserInterface
Clock
Database
Bootstrapper / Host
User Interface
18
Clock
• Standard implementation• Configurable interval• Start(), Stop(), Tick event
19
Database
• O/R bridging– Table per domain class– Column for public properties (discussion)– Associations converted to foreign keys
20
?
Bootstrap• Instantiation (create form, clock and universe
components)
• Event subscription
21
Domain in C# 3.0
22
Domain in C# 3.0
23
Universe class Methods
• TimerPassed() method - ‘Classic’
- Lambda:
24
Universe class Methods
• GetPlanetsInRange() Method
25
Universe class Methods
• GetPlanetsInRange() Method: Lambda
26
Universe class Methods
• GetPlanetsInRange() Method: LINQ
27
Form1 class Methods
28
DrawUniverse: Who is responsible?UI.DrawUniverse() vs
Universe.Draw()
Universe.Draw() Extension
29
Universe.Draw() Extension
30
Extension Methods: How
• Add a Static class to your namespace• Add static methods for each extension• Add a ‘this’ parameter to the ext. method
31
Refences
• DDD Masterclass (http://domaindrivendesign.nl)• Rebecca Wirfs-Brock: Object Design• Eric Evans: Domain Driven Design
• Blogs– http://born2code.net– http://whiletrue.nl– http://software-innovators.nl
32
33
top related