evolution of patterns
DESCRIPTION
Design and Implementation patterns have changed in object-oriented languages such as C# with the introduction of new language features, advances in object-oriented design, and the inclusion of functional language aspects. This session will explore the impact this has on design and implementation patterns and how they can be leveraged to build more elegant systems.TRANSCRIPT
![Page 1: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/1.jpg)
The Evolution of PatternsInfluences and Examples of Emerging Patterns
Chris Eargle
![Page 2: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/2.jpg)
Chris EargleTelerik Developer Evangelist
INETA Director
Microsoft MVP – Visual C#
MCPD, MCTS, etc
kodefuguru.com
![Page 3: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/3.jpg)
What is a Pattern?An element of reusable software
Names, motivates, and explains a general design that addresses recurring design problems
Describes the problem, the solution, when to apply the solution, and its consequences
304/11/2023
![Page 4: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/4.jpg)
Implementation LevelsInvisible Part of the language
Informal Referred to by name, but must be re-implemented for each use
Formal Implement pattern itself within the language
![Page 5: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/5.jpg)
InfluencesLanguage Features
Innovations in Object-Oriented Design
Other Programming Paradigms
![Page 6: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/6.jpg)
LanguageDesign patterns may be a sign of missing language features
![Page 7: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/7.jpg)
“16 of 23 patterns have qualitatively simpler implementation in Lisp or
Dylan than in C++ for at least some uses of each pattern.”
Peter Norvig
![Page 8: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/8.jpg)
Language FeaturesKeywords are added to languages
Typically streamlines a process
May be tied to other paradigms
![Page 9: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/9.jpg)
InnovationsObject-Oriented Programming is mature
Sometimes an idea takes hold…
challenges OO Principles…
and takes the community by storm.
![Page 10: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/10.jpg)
Fluent InterfacesUtilizes method chaining
Defined through the return value of a called method
Self referential - the new context is equivalent to the last context
![Page 11: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/11.jpg)
Fluent InterfacesEnglish-readable, left-to-right code
May violate command-query separation with stateful objects
Terminated through the return of a void context
![Page 12: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/12.jpg)
ParadigmsThere is a huge ecosystem of programming languages
Most languages fall into categories other than OO
These slowly make their way into modern OO languages
![Page 13: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/13.jpg)
GenericAlgorithms use types to be specified later
Reduces duplication
Pioneered by ADA in 1983
May be harder to understand
![Page 14: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/14.jpg)
TerminologyGenerics
Ada, Eiffel, Java, C#, F#, and Visual Basic .NET
Parametric Polymorphism
ML, Scala and Haskell
Templates
C++
![Page 15: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/15.jpg)
FunctionalTreats computation as the evaluation of functions
Avoids state and mutable data
Roots in lambda calculus
![Page 16: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/16.jpg)
Terminologyfirst class functions
functions can be passed as arguments
higher-order functions
take one or more functions as input
or outputs a function
combinators
takes one or more functions as input
and outputs a function
![Page 17: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/17.jpg)
“a combinator is a function which builds program fragments from
program fragments…”
John Hughes
![Page 18: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/18.jpg)
Terminologypure functions
no side effects, which means the function called with the same arguments returns the same result
anonymous functions
a function defined, and possibly called, without being bound to an identifier.
continuation-passing style
when a function is complete, the computation is passed to a continuation function
![Page 19: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/19.jpg)
Singleton
![Page 20: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/20.jpg)
Singleton PatternRestricts class instantiation to one instance
Useful when only one instance is needed in system
Some consider this an anti-pattern
Not the same as a static class
2004/11/2023
![Page 21: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/21.jpg)
Singleton Diagram
- Singleton()S+ Instance
Singleton<<singleton>>
Retrieves a single, maintained instance of class.
![Page 22: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/22.jpg)
Influence on LanguageA few modern languages directly implement this construct
![Page 23: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/23.jpg)
Scala Example
// Singleton uses the object keyword instead of classobject Utilities { val test = "Test App" def loadImages() = { // ... } def createManager():EntityManager = { // ... }}
![Page 24: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/24.jpg)
Lazy Initialization
![Page 25: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/25.jpg)
Lazy InitializationDelays creation of an object
Use when eager initialization is resource intensive
Often used with a factory method (more later)
![Page 26: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/26.jpg)
Iterator
![Page 27: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/27.jpg)
Iterator Patterniterator an object that provides a standard way to
examine all element of any collection.
Has a uniform interface for traversing many data structure without exposing their implementations.
Supports concurrent iteration and element removal.
No need to know the internal structure of collection.
![Page 28: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/28.jpg)
Iterator Diagram
+ CreateIterator()
Aggregate<<interface>>
+ First()+ Next()+ IsDone()+ CurrentItem
Iterator<<interface>>
+ CreateIterator()
ConcreteAggregate ConcreteIterator
Client
![Page 29: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/29.jpg)
Command
![Page 30: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/30.jpg)
Command Patternused to represent and encapsulate all the information needed to call a method at a later time
![Page 31: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/31.jpg)
Terminologyclient
instantiates the command object and provides the information required to call the method at a later time.
invoker
decides when the method should be called
receiver
instance of the class that contains the method's code
![Page 32: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/32.jpg)
Command DiagramInvoker
+ Execute()
Command<<interface>>
+ Action()
Receiver
+ Execute()
ConcreteCommand
Invoker
![Page 33: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/33.jpg)
Fluent CommandThe Execute method return the object
Enables quick access to return properties
3304/11/2023
command.Execute(); var results = command.Results;
var results = command.Execute()
.Results;
![Page 34: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/34.jpg)
Delegate CommandExecute is accepted as a function
![Page 35: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/35.jpg)
Factory
![Page 36: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/36.jpg)
Factory MethodMethod used to create an object
Used when it is more complex to simply instantiate
Don’t confuse this with abstract factory, a generalized pattern for building a series of factories
Useful in C# to take advantage of generic inference
![Page 37: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/37.jpg)
Function FactoryCombinators correspond to factory methods for functions
![Page 38: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/38.jpg)
Factory FunctionUtilizes a function to create an object
![Page 39: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/39.jpg)
Strategy
![Page 40: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/40.jpg)
Strategy PatternDefines family of algorithms
Encapsulates algorithms to make them interchangeable
![Page 41: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/41.jpg)
Strategy Diagram
ContextInterface()
Context
AlgorithmInterface()
Strategy<<interface>>
AlgorithmInterface()
ConcreteStrategyB<<implementation>>
AlgorithmInterface()
ConcreteStrategyA<<implementation>>
<<implements>> <<implements>>
Containment
Use
![Page 42: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/42.jpg)
Function StrategyWhen a strategy is required, allow owner to pass in a function
Prevents class explosion
Enables flexibility
4204/11/2023
![Page 43: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/43.jpg)
Function Strategy
ContextInterface()
ContextStrategy
<<delegate>>Containment
Use
![Page 44: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/44.jpg)
Template Method
![Page 45: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/45.jpg)
Template PatternDefines the program skeleton of an algorithm
Encapsulate what changes and make it abstract
Subclasses implement those steps in the algorithm
![Page 46: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/46.jpg)
Template Diagram
A+ PrimitiveOperation1()A+ PrimitiveOperation2 ()+ TemplateMethod()
AbstractClass
+ PrimitiveOperation1()+ PrimitiveOperation2()
ConcreteClass
![Page 47: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/47.jpg)
Function TemplateEncapsulate what changes into functions
Allow owner to specify those pieces of the algorithm
Prevents class explosion
4704/11/2023
![Page 48: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/48.jpg)
ReferencesOnline references and source code can be found at bitly.com/wHIBI0
![Page 49: Evolution of Patterns](https://reader036.vdocuments.mx/reader036/viewer/2022062703/554f6b92b4c905c8088b5204/html5/thumbnails/49.jpg)
ReferencesPatterns of Enterprise Application Architecture
-Martin Fowler
Revenge of the Nerds
-Paul Graham
Object World, May 5 1996
-Peter Norvig
Functional thinking: Functional design patterns, Part 1
-Neal Ford
Generalising Monads to Arrows
-John Hughes
Design Patterns: Elements of Reusable Object-Oriented Software
-GoF