Evolution of Patterns


Published on

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.

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • These three levels are from Peter Norvig’s articles in Object World.
  • generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters. This approach, pioneered by Ada in 1983, permits writing common functions or types that differ only in the set of types on which they operate when used, thus reducing duplication. The Gang of Four noted that this technique, especially when combined with delegation, is very powerful but that "[dynamic], highly parameterized software is harder to understand than more static software."[1]
  • Evolution of Patterns

    1. The Evolution of Patterns Influences and Examples of Emerging Patterns Chris Eargle
    2. Chris EargleTelerik Developer EvangelistINETA DirectorMicrosoft MVP – Visual C#MCPD, MCTS, etckodefuguru.comkodefuguru@live.com
    3. 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 consequences3/17/2012 3
    4. Implementation LevelsInvisible Part of the languageInformal Referred to by name, but must be re- implemented for each useFormal Implement pattern itself within the language
    5. InfluencesLanguage FeaturesInnovations in Object-Oriented DesignOther Programming Paradigms
    6. LanguageDesign patterns may be a sign of missing languagefeatures
    7. “16 of 23 patterns have qualitatively simpler implementation in Lisp orDylan than in C++ for at least some uses of each pattern.” Peter Norvig
    8. Language FeaturesKeywords are added to languagesTypically streamlines a processMay be tied to other paradigms
    9. InnovationsObject-Oriented Programming is matureSometimes an idea takes hold… challenges OO Principles… and takes the community by storm.
    10. Fluent InterfacesUtilizes method chainingDefined through the return value of a called methodSelf referential - the new context is equivalent to thelast context
    11. Fluent InterfacesEnglish-readable, left-to-right codeMay violate command-query separation with statefulobjectsTerminated through the return of a void context
    12. ParadigmsThere is a huge ecosystem of programming languagesMost languages fall into categories other than OOThese slowly make their way into modern OOlanguages
    13. GenericAlgorithms use types to be specified laterReduces duplicationPioneered by ADA in 1983May be harder to understand
    14. TerminologyGenerics Ada, Eiffel, Java, C#, F#, and Visual Basic .NETParametric Polymorphism ML, Scala and HaskellTemplates C++
    15. FunctionalTreats computation as the evaluation of functionsAvoids state and mutable dataRoots in lambda calculus
    16. Terminologyfirst class functions functions can be passed as argumentshigher-order functions take one or more functions as input or outputs a functioncombinators takes one or more functions as input and outputs a function
    17. “a combinator is a function which builds program fragments from program fragments…” John Hughes
    18. Terminologypure functions no side effects, which means the function called with the same arguments returns the same resultanonymous 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
    19. Singleton
    20. Singleton Pattern Restricts 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 class3/17/2012 20
    21. Singleton Diagram Singleton Retrieves a single, <<singleton>> maintained instance of class. - Singleton() S+ Instance
    22. Influence on LanguageA few modern languages directly implement thisconstruct
    23. Scala Example// Singleton uses the object keyword instead of classobject Utilities { val test = "Test App" def loadImages() = { // ... } def createManager():EntityManager = { // ... }}
    24. Lazy Initialization
    25. Lazy InitializationDelays creation of an objectUse when eager initialization is resource intensiveOften used with a factory method (more later)
    26. Iterator
    27. Iterator Patterniterator an object that provides a standard way to examine all element of any collection.Has a uniform interface for traversing many datastructure without exposing their implementations.Supports concurrent iteration and element removal.No need to know the internal structure of collection.
    28. Iterator Diagram Aggregate Client Iterator <<interface>> <<interface>>+ CreateIterator() + First() + Next() + IsDone() + CurrentItem ConcreteAggregate ConcreteIterator+ CreateIterator()
    29. Command
    30. Command Patternused to represent and encapsulate all the informationneeded to call a method at a later time
    31. 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 calledreceiver instance of the class that contains the methods code
    32. Command Diagram Invoker Command <<interface>> + Execute() Invoker Receiver ConcreteCommand + Action() + Execute()
    33. Fluent Command The Execute method return the object Enables quick access to return properties command.Execute(); var results = command.Execute() var results = command.Results; .Results;3/17/2012 33
    34. Delegate CommandExecute is accepted as a function
    35. Factory
    36. Factory MethodMethod used to create an objectUsed when it is more complex to simply instantiateDon’t confuse this with abstract factory, a generalizedpattern for building a series of factoriesUseful in C# to take advantage of generic inference
    37. Function FactoryCombinators correspond to factory methods forfunctions
    38. Factory FunctionUtilizes a function to create an object
    39. Strategy
    40. Strategy PatternDefines family of algorithmsEncapsulates algorithms to make theminterchangeable
    41. Strategy Diagram Containment Strategy Context <<interface>>ContextInterface() Use AlgorithmInterface() <<implements>> <<implements>> ConcreteStrategyA ConcreteStrategyB <<implementation>> <<implementation>> AlgorithmInterface() AlgorithmInterface()
    42. Function Strategy When a strategy is required, allow owner to pass in a function Prevents class explosion Enables flexibility3/17/2012 42
    43. Function Strategy Containment Strategy Context <<delegate>> ContextInterface() Use
    44. Template Method
    45. Template PatternDefines the program skeleton of an algorithmEncapsulate what changes and make it abstractSubclasses implement those steps in the algorithm
    46. Template Diagram AbstractClass A+ PrimitiveOperation1() A+ PrimitiveOperation2 () + TemplateMethod() ConcreteClass + PrimitiveOperation1() + PrimitiveOperation2()
    47. Function Template Encapsulate what changes into functions Allow owner to specify those pieces of the algorithm Prevents class explosion3/17/2012 47
    48. ReferencesOnline references and source code can be found atbitly.com/wHIBI0
    49. ReferencesPatterns of Enterprise Functional thinking: FunctionalApplication Architecture design patterns, Part 1 -Martin Fowler -Neal FordRevenge of the Nerds Generalising Monads to Arrows -Paul Graham -John HughesObject World, May 5 1996 Design Patterns: Elements of -Peter Norvig Reusable Object-Oriented Software -GoF