Glass V4, More Info For Your Solution
Mike Edwards Glass
@mikeedwards83@glasslu
Sitecore User Group Conference 2015 1
Glass V4, More Info For Your Solution
ModelingMike Edwards Glass
@mikeedwards83@glasslu
Sitecore User Group Conference 2015 2
Hello!
Sitecore User Group Conference 2015 3
Mike EdwardsSitecore MVP@mikeedwards83@glasslu
Modelling
Sitecore User Group Conference 2015 4
NOT THIS KIND
Modelling
Sitecore User Group Conference 2015 5
THIS KIND
Modelling
• Different Patterns• Common Mistakes• Techniques
Sitecore User Group Conference 2015 6
Common Patterns
• Active Record• Data Mapping• Wrapping
Sitecore User Group Conference 2015 7
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
Active Record Pattern
Sitecore User Group Conference 2015 9
The Example
Active Record Pattern - Pro’s
Simple to use:
Sitecore User Group Conference 2015 10
Active Record Pattern - Pro’s
Simple to pass around:
Sitecore User Group Conference 2015 11
Hidden side effects:
Active Record Pattern - Con’s
Sitecore User Group Conference 2015 12
Surprise!!Pointless
Active Record Pattern - Cons
Coupled to data source:
Sitecore User Group Conference 2015 13
Active Record Pattern - Con’s
Complex:
Sitecore User Group Conference 2015 14
Active Record Pattern - Con’s
Hard to test:
Sitecore User Group Conference 2015 15
How do we mock this??
Ask the FakeDBGuys
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 FowlerSitecore User Group Conference 2015 16
Data Mapper Pattern
Sitecore User Group Conference 2015 17
The Example
Data Mapper Pattern
Sitecore User Group Conference 2015 18
The Example
Data Mapper Pattern
Sitecore User Group Conference 2015 19
The Example
Data Mapper Pattern
Simple Models
Sitecore User Group Conference 2015 20
Data Mapper Pattern - Pro’s
Easy Testing
Sitecore User Group Conference 2015 21
Data Mapper Pattern - Pro’s
Clear Separation
Sitecore User Group Conference 2015 22
My World Their World
Data Mapper Pattern - Pro’s
Store Anywhere
Sitecore User Group Conference 2015 23
Data Mapper Pattern - Pro’s
Clear Control
Sitecore User Group Conference 2015 24
Hello!!
Data Mapper Pattern - Con’s
Map Unused Data
Sitecore User Group Conference 2015 25
Data Mapper Pattern - Con’s
Expensive Upfront
Sitecore User Group Conference 2015 26
Data Mapper Pattern - Con’s
Disconnection from source
Sitecore User Group Conference 2015 27
Where the hell did youcome from?
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
Wrappers Models
Sitecore User Group Conference 2015 29
Wrappers Models - Pro’s
Cheap Up Front
Sitecore User Group Conference 2015 30
No work done here!
Only accessed propertiesrequire conversion.
Wrappers Models - Pro’s
Hidden State Changes
Sitecore User Group Conference 2015 31
What happens if this changes
Wrappers Models - Pro’s
Hidden State Changes
Sitecore User Group Conference 2015 32
Are these the same?
Wrappers Models - Con’s
Testing Difficulty
Sitecore User Group Conference 2015 33
Can’t test becauseof this.
Have to write data conversion code
Need to understandthis
Wrappers Models - Meet my partner
Coupling
Sitecore User Group Conference 2015 34
I ask for this
Wrappers Models - Meet my partner
Coupling
Sitecore User Group Conference 2015 35
I get this
Common Problems
• Anemic domain model • Bloated domain model• Skinny domain model• Indiscreet domain model
Sitecore User Group Conference 2015 36
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
Anemic Domain Model - Example
Sitecore User Group Conference 2015 38
Feed Me!!
Anemic Domain Model
Sitecore User Group Conference 2015 39
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
Bloated Domain Model
Sitecore User Group Conference 2015 41
Bloated Domain Model
Fixed
Sitecore User Group Conference 2015 42
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
Skinny Domain Model
Skinny Domain model
Sitecore User Group Conference 2015 44
Skinny Domain Model
Fixed
Sitecore User Group Conference 2015 45
USE THE RAW API!
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
Indiscreet Domain Model
Sitecore User Group Conference 2015 47
Indiscreet Domain Model
Fixed
Sitecore User Group Conference 2015 48
Techniques
Sitecore User Group Conference 2015 49
• Interface Models• Template Models• Rendering Models• MVC• MVP
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.
Interface Models
Sitecore User Group Conference 2015 51
Interface Models
• Multiple Inheritance• Very little code
• Often Anemic• Indiscreet
Sitecore User Group Conference 2015 52
Interface Models
Sitecore User Group Conference 2015 53
Spoofing Logic
Template Models
Sitecore User Group Conference 2015 54
Template Models
• Code generation friendly• Easy to sync• Bloated• Indiscreet• Anemic
Sitecore User Group Conference 2015 55
Rendering Models
Sitecore User Group Conference 2015 56
Rendering Models
• Use case specific• Minimum number of properties• Custom methods• Model explosion• Magic Properties Problem• Skinny
Sitecore User Group Conference 2015 57
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.
- - WikiSitecore User Group Conference 2015 58
MVC Models
What do we pass to the view?
Sitecore User Group Conference 2015 59
MVC Models
The View Model• Explicitly defines the contract• Easy to expand• Use convention• Separates Domain from View
Sitecore User Group Conference 2015 60
MVC Models
Sitecore User Group Conference 2015 61
Easy to find
MVC Models
Sitecore User Group Conference 2015 62
Easy to identify!
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
MVP
Sitecore User Group Conference 2015 64
MVP is similar to MVC
Sitecore User Group Conference 2015 65
MVP or MVC?
Sitecore User Group Conference 2015 66
Finished!!Questions?
Sitecore User Group Conference 2015 67
68
Find Me:
Sitecore User Group Conference 2015 68
Mike EdwardsSitecore MVP
@mikeedwards83@glasslu
[Reserved for sponsor logo’s]
Sitecore User Group Conference 2015 69
Sitecore User Group Conference 2015 69
Thank you
Top Related