design patterns on sitecore: the good, the bad and the ugly

26
Click icon to add picture Design Patterns on Sitecore: The Good, the Bad and the Ugly Mike Reynolds

Upload: michael-reynolds

Post on 15-Apr-2017

560 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Design Patterns on Sitecore: The Good, the Bad and the Ugly

Click icon to add picture

Design Patterns on Sitecore: The Good, the Bad and the UglyMike Reynolds

Page 2: Design Patterns on Sitecore: The Good, the Bad and the Ugly

© 2016 Sitecore User Group Conference Europe and its respective speakers. All rights reserved.

• “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!

What’s a Design Pattern?

Page 3: Design Patterns on Sitecore: The Good, the Bad and the Ugly

© 2016 Sitecore User Group Conference Europe and its respective speakers. All rights reserved.

• 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)

Design Patterns: History

Page 4: Design Patterns on Sitecore: The Good, the Bad and the Ugly

© 2016 Sitecore User Group Conference Europe and its respective speakers. All rights reserved.

Are Design Patterns Always Good?

Page 5: Design Patterns on Sitecore: The Good, the Bad and the Ugly

© 2016 Sitecore User Group Conference Europe and its respective speakers. All rights reserved.

Are Design Patterns Always Good?

Page 6: Design Patterns on Sitecore: The Good, the Bad and the Ugly

© 2016 Sitecore User Group Conference Europe and its respective speakers. All rights reserved.

Are Design Patterns Always Good?

Page 7: Design Patterns on Sitecore: The Good, the Bad and the Ugly

© 2016 Sitecore User Group Conference Europe and its respective speakers. All rights reserved.

• Encapsulates an object with the same interface• Also a “wrapper”

• Adds/removes/alters functionality on the inner instance

Decorator Pattern

Page 8: Design Patterns on Sitecore: The Good, the Bad and the Ugly

© 2016 Sitecore User Group Conference Europe and its respective speakers. All rights reserved.

Decorator Pattern

Page 9: Design Patterns on Sitecore: The Good, the Bad and the Ugly

Click icon to add picture

Decorator PatternLet’s see some code!

9

Page 10: Design Patterns on Sitecore: The Good, the Bad and the Ugly

© 2016 Sitecore User Group Conference Europe and its respective speakers. All rights reserved.

Decorator Pattern

Page 11: Design Patterns on Sitecore: The Good, the Bad and the Ugly

© 2016 Sitecore User Group Conference Europe and its respective speakers. All rights reserved.

Decorator Pattern

Page 12: Design Patterns on Sitecore: The Good, the Bad and the Ugly

© 2016 Sitecore User Group Conference Europe and its respective speakers. All rights reserved.

Decorator Pattern

Page 13: Design Patterns on Sitecore: The Good, the Bad and the Ugly

© 2016 Sitecore User Group Conference Europe and its respective speakers. All rights reserved.

Decorator Pattern

Page 14: Design Patterns on Sitecore: The Good, the Bad and the Ugly

© 2016 Sitecore User Group Conference Europe and its respective speakers. All rights reserved.

• Defines the main “algorithm” in an abstract base class

• Provides stubs (abstract methods) for subclasses to “fill in the blanks”

• May also offer hooks (virtual methods)• Can further alter the main “algorithm”

Template Method Pattern

Page 15: Design Patterns on Sitecore: The Good, the Bad and the Ugly

© 2016 Sitecore User Group Conference Europe and its respective speakers. All rights reserved.

Template Method Pattern

Page 16: Design Patterns on Sitecore: The Good, the Bad and the Ugly

Click icon to add picture

Template Method Pattern

Let’s see some code!

16

Page 17: Design Patterns on Sitecore: The Good, the Bad and the Ugly

© 2016 Sitecore User Group Conference Europe and its respective speakers. All rights reserved.

Template Method Pattern

Page 18: Design Patterns on Sitecore: The Good, the Bad and the Ugly

© 2016 Sitecore User Group Conference Europe and its respective speakers. All rights reserved.

Template Method Pattern

Page 19: Design Patterns on Sitecore: The Good, the Bad and the Ugly

© 2016 Sitecore User Group Conference Europe and its respective speakers. All rights reserved.

Template Method Pattern

Page 20: Design Patterns on Sitecore: The Good, the Bad and the Ugly

© 2016 Sitecore User Group Conference Europe and its respective speakers. All rights reserved.

Template Method Pattern

Page 21: Design Patterns on Sitecore: The Good, the Bad and the Ugly

© 2016 Sitecore User Group Conference Europe and its respective speakers. All rights reserved.

Template Method Pattern

Page 22: Design Patterns on Sitecore: The Good, the Bad and the Ugly

© 2016 Sitecore User Group Conference Europe and its respective speakers. All rights reserved.

Template Method Pattern

Page 23: Design Patterns on Sitecore: The Good, the Bad and the Ugly

© 2016 Sitecore User Group Conference Europe and its respective speakers. All rights reserved.

• Defines a family of classes with the same interface

• Encapsulates each class instance

• Makes the instances interchangeable within that family

Strategy Pattern

Page 24: Design Patterns on Sitecore: The Good, the Bad and the Ugly

© 2016 Sitecore User Group Conference Europe and its respective speakers. All rights reserved.

Strategy Pattern

Page 25: Design Patterns on Sitecore: The Good, the Bad and the Ugly

Click icon to add picture

Strategy Pattern

Let’s see some code!

25

Page 26: Design Patterns on Sitecore: The Good, the Bad and the Ugly

Thank you!Twitter: @mike_i_reynolds

Sitecore Slack: @sitecorejunkieLinkedIn: http://bit.ly/1Csu1N8Blog: http://sitecorejunkie.com

Get in Touch: