Attain Clean Code in
Sitecore Solutions using
Design Patterns
Mike Reynolds
Hanson Dodge Creative
@mike_i_reynolds
Sitecore User Group Conference 2015 1
What’s a Design Pattern?
• “General reusable solution to a commonly occurring problem“
• http://en.wikipedia.org/wiki/Software_design_pattern
• Describes how to solve a problem
• Can be across different contexts
• Provides a common language for developers
• Is not a cookie-cutter code solution!
Sitecore User Group Conference 2015 2
Design Patterns: History
• Proposed by Christopher Alexander (1970s)
• A Pattern Language: Towns, Buildings, Construction
(http://amzn.to/1BtaaIH)
• Kent Beck and Ward Cunningham applied the concept to
programming (1987)
• Presented results at Object-Oriented Programming, Systems,
Languages & Applications (OOPSLA)
Sitecore User Group Conference 2015 3
Design Patterns: History
• Gang of Four (GoF) Book (1994)
• Design Patterns: Elements of Reusable Object-Oriented Software.
(http://amzn.to/UPNN2F)
• Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides
Sitecore User Group Conference 2015 4
Design Patterns: Examples
• Adapter
• Decorator
• Composite
• Chain-of-responsibility
• Null Object
Sitecore User Group Conference 2015 5
Adapter Pattern
• Allows the interface of an existing class to be used from another
• A “wrapper”
• Makes existing classes work with others without modifying their
source code
Sitecore User Group Conference 2015 6
Adapter Pattern
Sitecore User Group Conference 2015 7
Decorator Pattern
• Encapsulates an object with the same interface
• Also a “wrapper”
• Adds/removes/alters functionality on the inner instance
Sitecore User Group Conference 2015 8
Decorator Pattern
Sitecore User Group Conference 2015 9
Composite Pattern
• Encapsulates a collection of objects with the same interface
• Treats the entire collection as one object
Sitecore User Group Conference 2015 10
Composite Pattern
Sitecore User Group Conference 2015 11
Chain-of-responsibility Pattern
• Composed of command objects and a series of processing
objects
• Each processing object executes specific command objects
• Processing objects are chained together
• think linked list
• Processing objects are invoked in a cascading manner
Sitecore User Group Conference 2015 12
Null Object Pattern
• Represents the “null” state of an object
• Provides methods with no behaviour
• Removes the need of client code performing null checks
Sitecore User Group Conference 2015 13
Learn More!
• Recommend Books
• http://amzn.to/UPNN2F
• http://amzn.to/1ppJHeH
• http://amzn.to/1EZEa3z
• http://amzn.to/1bSAYsh
• Blog posts
• http://bit.ly/1E7J7JO
Sitecore User Group Conference 2015 14
Get In Touch!
Blog: http://sitecorejunkie.com
Twitter: @mike_i_reynolds
LinkedIn: http://linkd.in/1Csu1N8
Sitecore User Group Conference 2015 15
Questions?
Sitecore User Group Conference 2015 16
Thank you
Sitecore User Group Conference 2015 17

Attain Clean Code in Sitecore Solutions using Design Patterns

  • 1.
    Attain Clean Codein Sitecore Solutions using Design Patterns Mike Reynolds Hanson Dodge Creative @mike_i_reynolds Sitecore User Group Conference 2015 1
  • 2.
    What’s a DesignPattern? • “General reusable solution to a commonly occurring problem“ • http://en.wikipedia.org/wiki/Software_design_pattern • Describes how to solve a problem • Can be across different contexts • Provides a common language for developers • Is not a cookie-cutter code solution! Sitecore User Group Conference 2015 2
  • 3.
    Design Patterns: History •Proposed by Christopher Alexander (1970s) • A Pattern Language: Towns, Buildings, Construction (http://amzn.to/1BtaaIH) • Kent Beck and Ward Cunningham applied the concept to programming (1987) • Presented results at Object-Oriented Programming, Systems, Languages & Applications (OOPSLA) Sitecore User Group Conference 2015 3
  • 4.
    Design Patterns: History •Gang of Four (GoF) Book (1994) • Design Patterns: Elements of Reusable Object-Oriented Software. (http://amzn.to/UPNN2F) • Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides Sitecore User Group Conference 2015 4
  • 5.
    Design Patterns: Examples •Adapter • Decorator • Composite • Chain-of-responsibility • Null Object Sitecore User Group Conference 2015 5
  • 6.
    Adapter Pattern • Allowsthe interface of an existing class to be used from another • A “wrapper” • Makes existing classes work with others without modifying their source code Sitecore User Group Conference 2015 6
  • 7.
    Adapter Pattern Sitecore UserGroup Conference 2015 7
  • 8.
    Decorator Pattern • Encapsulatesan object with the same interface • Also a “wrapper” • Adds/removes/alters functionality on the inner instance Sitecore User Group Conference 2015 8
  • 9.
    Decorator Pattern Sitecore UserGroup Conference 2015 9
  • 10.
    Composite Pattern • Encapsulatesa collection of objects with the same interface • Treats the entire collection as one object Sitecore User Group Conference 2015 10
  • 11.
    Composite Pattern Sitecore UserGroup Conference 2015 11
  • 12.
    Chain-of-responsibility Pattern • Composedof command objects and a series of processing objects • Each processing object executes specific command objects • Processing objects are chained together • think linked list • Processing objects are invoked in a cascading manner Sitecore User Group Conference 2015 12
  • 13.
    Null Object Pattern •Represents the “null” state of an object • Provides methods with no behaviour • Removes the need of client code performing null checks Sitecore User Group Conference 2015 13
  • 14.
    Learn More! • RecommendBooks • http://amzn.to/UPNN2F • http://amzn.to/1ppJHeH • http://amzn.to/1EZEa3z • http://amzn.to/1bSAYsh • Blog posts • http://bit.ly/1E7J7JO Sitecore User Group Conference 2015 14
  • 15.
    Get In Touch! Blog:http://sitecorejunkie.com Twitter: @mike_i_reynolds LinkedIn: http://linkd.in/1Csu1N8 Sitecore User Group Conference 2015 15
  • 16.
  • 17.
    Thank you Sitecore UserGroup Conference 2015 17

Editor's Notes

  • #2 DO NOT REMOVE THIS SLIDE
  • #18 DO NOT REMOVE THIS SLIDE