The document discusses different patterns for modeling data in Sitecore applications, including active record, data mapper, and wrapper patterns. It notes pros and cons of each pattern, such as active record being simple to use but difficult to test. Common problems with domain models like anemic, bloated, skinny, and indiscreet models are also covered. The document concludes with an overview of techniques like interface models, template models, rendering models, and MVC/MVP patterns.
8. Active Record Pattern
In software engineering, the active record pattern is an
architectural pattern found in software that stores in-memory
object data in relational databases. The interface of an object
conforming to this pattern would include functions such as
Insert, Update, and Delete.
- Wiki, Martin Fowler
Sitecore User Group Conference 2015 8
15. Active Record Pattern - Con’s
Hard to test:
Sitecore User Group Conference 2015 15
How do we
mock this??
Ask the FakeDB
Guys
16. Data Mapper Pattern
Data Mapper is a Data Access Layer that performs bidirectional
transfer of data between a persistent data store (often a
relational database) and an in memory data representation (the
domain layer). The goal of the pattern is to keep the in memory
representation and the persistent data store independent of
each other and the data mapper itself.
- Wiki, Martin Fowler
Sitecore User Group Conference 2015 16
21. Data Mapper Pattern - Pro’s
Easy Testing
Sitecore User Group Conference 2015 21
22. Data Mapper Pattern - Pro’s
Clear Separation
Sitecore User Group Conference 2015 22
My World Their World
23. Data Mapper Pattern - Pro’s
Store Anywhere
Sitecore User Group Conference 2015 23
24. Data Mapper Pattern - Pro’s
Clear Control
Sitecore User Group Conference 2015 24
Hello!!
25. Data Mapper Pattern - Con’s
Map Unused Data
Sitecore User Group Conference 2015 25
26. Data Mapper Pattern - Con’s
Expensive Upfront
Sitecore User Group Conference 2015 26
27. Data Mapper Pattern - Con’s
Disconnection from source
Sitecore User Group Conference 2015 27
Where the hell did you
come from?
28. Wrappers Models
Wraps the underlying data source and converts the data on
demand. The internal model contains a reference to the original
data source which it uses to perform data conversion.
Sitecore User Group Conference 2015 28
30. Wrappers Models - Pro’s
Cheap Up Front
Sitecore User Group Conference 2015 30
No work done here!
Only accessed properties
require conversion.
31. Wrappers Models - Pro’s
Hidden State Changes
Sitecore User Group Conference 2015 31
What happens if this
changes
32. Wrappers Models - Pro’s
Hidden State Changes
Sitecore User Group Conference 2015 32
Are these the same?
33. Wrappers Models - Con’s
Testing Difficulty
Sitecore User Group Conference 2015 33
Can’t test because
of this.
Have to write
data conversion code
Need to understand
this
34. Wrappers Models - Meet my partner
Coupling
Sitecore User Group Conference 2015 34
I ask for this
35. Wrappers Models - Meet my partner
Coupling
Sitecore User Group Conference 2015 35
I get this
36. Common Problems
• Anemic domain model
• Bloated domain model
• Skinny domain model
• Indiscreet domain model
Sitecore User Group Conference 2015 36
37. Anemic Domain Model
Anemic domain model is the use of a software domain model
where the domain objects contain little or no business logic
(validations, calculations, business rules etc).
- Wiki, Martin Fowler
Sitecore User Group Conference 2015 37
38. Anemic Domain Model - Example
Sitecore User Group Conference 2015 38
Feed Me!!
40. Bloated Domain Model
A Bloated Domain Model is the use of a software domain model
that contains a large number of properties that are never access
or required by the application.
- Mike E
Sitecore User Group Conference 2015 40
43. Skinny Domain Model
A Skinny Domain Model is the use of a software domain model
that contains one or very few properties.
- Mike
Sitecore User Group Conference 2015 43
46. Indiscreet Domain Model
A Indiscreet Domain Model is the use of a software domain
model that exposes all it’s properties publically even if they
should or should not be accessed by external code.
- Mike E
Sitecore User Group Conference 2015 46
50. Interface Models
Sitecore User Group Conference 2015 50
Domain models defined using interfaces only. Interface are
dynamically implemented at run time using a proxy framework.
57. Rendering Models
• Use case specific
• Minimum number of properties
• Custom methods
• Model explosion
• Magic Properties Problem
• Skinny
Sitecore User Group Conference 2015 57
58. MVC Models
Model–view–controller (MVC) is a software architectural
pattern for implementing user interfaces. It divides a given
software application into three interconnected parts, so as to
separate internal representations of information from the ways
that information is presented to or accepted from the user.
- - Wiki
Sitecore User Group Conference 2015 58
59. MVC Models
What do we pass to the view?
Sitecore User Group Conference 2015 59
60. MVC Models
The View Model
• Explicitly defines the contract
• Easy to expand
• Use convention
• Separates Domain from View
Sitecore User Group Conference 2015 60
63. And don’t forget MVP!
MVP is a user interface architectural pattern engineered to
facilitate automated unit testing and improve the separation of
concerns in presentation logic.
- Wiki
Sitecore User Group Conference 2015 63