Visitor
                  Steve Hayes
                Cogent Consulting




 Copyright Cogent Consulting Pty Ltd (http://w...
The Problem



 Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative Commons...
Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative Commons Attribution-Non...
Show me everything in a consistent manner...




             Copyright Cogent Consulting Pty Ltd (http://www.cogentconsul...
Show me everything in a consistent manner...

      ... and send it to my friend via email




             Copyright Coge...
Show me everything in a consistent manner...

      ... and send it to my friend via email

   oh, and send it to her phon...
Show me everything in a consistent manner...

      ... and send it to my friend via email

   oh, and send it to her phon...
Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative Commons Attribution-Non...
Some analysis music please...




              Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
 ...
Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative Commons Attribution-Non...
Commonality is in the eye of the beholder




         Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.co...
Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative Commons Attribution-Non...
With a little casual application of
        polymorphism...




     Copyright Cogent Consulting Pty Ltd (http://www.cogen...
Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative Commons Attribution-Non...
Does this look bad to you?




             Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
     ...
The solution



 Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative Common...
Visitors



    Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
   Licensed under a Creative Comm...
“Represent an operation to be performed
 on the elements of an object structure.
 Visitor lets you define a new operation
 ...
Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative Commons Attribution-Non...
A solution to a problem in a context




      Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
  ...
Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative Commons Attribution-Non...
Headings, Details, ...




 Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Crea...
and the Iterator




 Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative C...
Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative Commons Attribution-Non...
Let’s show it in code!




 Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Crea...
Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative Commons Attribution-Non...
Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative Commons Attribution-Non...
Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative Commons Attribution-Non...
Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative Commons Attribution-Non...
Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative Commons Attribution-Non...
Time for visitors...




          Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
         Licen...
Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative Commons Attribution-Non...
Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative Commons Attribution-Non...
Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative Commons Attribution-Non...
Melbourne Pushes Boundaries

The Wolves in the Wall

Redhill Consulting Pty Ltd - Ruby on Rails Plugins

Let's talk about ...
Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative Commons Attribution-Non...
Melbourne Pushes Boundaries
Tim Colebatch
Melbourne is experiencing its biggest growth surge
since the 1960's

The Wolves ...
Cool!



   Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
  Licensed under a Creative Commons A...
When?



 Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative Commons Attri...
“an object structure contains many classes
  of objects with differing interfaces, and
you want to perform operations on t...
Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative Commons Attribution-Non...
“many distinct and unrelated operations
  need to be performed on objects in an
 object structure, and you want to avoid
 ...
Show me everything in a consistent manner...

      ... and send it to my friend via email

   oh, and send it to her phon...
“the classes defining the object structure
    rarely change, but you often want to
define new operations over the structure...
Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative Commons Attribution-Non...
Consequences



 Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative Common...
Visitor makes adding new operations easy




         Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com...
A visitor gathers related operations and
        separates unrelated ones




        Copyright Cogent Consulting Pty Ltd ...
Adding new ConcreteElement classes is
               hard




       Copyright Cogent Consulting Pty Ltd (http://www.cogen...
Visitors can cross object hierarchies




      Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
 ...
Visitors can accumulate state




   Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
  Licensed u...
Visitors may compromise encapsulation




       Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
...
Discussion



 Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au)
Licensed under a Creative Commons ...
Upcoming SlideShare
Loading in …5
×

Visitor Pattern By Steve Hayes

1,690 views
1,611 views

Published on

Published in: Technology, Business
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,690
On SlideShare
0
From Embeds
0
Number of Embeds
24
Actions
Shares
0
Downloads
85
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Visitor Pattern By Steve Hayes

  1. 1. Visitor Steve Hayes Cogent Consulting Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  2. 2. The Problem Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  3. 3. Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  4. 4. Show me everything in a consistent manner... Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  5. 5. Show me everything in a consistent manner... ... and send it to my friend via email Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  6. 6. Show me everything in a consistent manner... ... and send it to my friend via email oh, and send it to her phone as well... Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  7. 7. Show me everything in a consistent manner... ... and send it to my friend via email oh, and send it to her phone as well... and print it..... Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  8. 8. Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  9. 9. Some analysis music please... Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  10. 10. Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  11. 11. Commonality is in the eye of the beholder Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  12. 12. Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  13. 13. With a little casual application of polymorphism... Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  14. 14. Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  15. 15. Does this look bad to you? Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  16. 16. The solution Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  17. 17. Visitors Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  18. 18. “Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates” -- GOF Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  19. 19. Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  20. 20. A solution to a problem in a context Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  21. 21. Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  22. 22. Headings, Details, ... Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  23. 23. and the Iterator Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  24. 24. Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  25. 25. Let’s show it in code! Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  26. 26. Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  27. 27. Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  28. 28. Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  29. 29. Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  30. 30. Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  31. 31. Time for visitors... Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  32. 32. Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  33. 33. Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  34. 34. Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  35. 35. Melbourne Pushes Boundaries The Wolves in the Wall Redhill Consulting Pty Ltd - Ruby on Rails Plugins Let's talk about tests, baby... Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  36. 36. Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  37. 37. Melbourne Pushes Boundaries Tim Colebatch Melbourne is experiencing its biggest growth surge since the 1960's The Wolves in the Wall 12.06 Redhill Consulting Pty Ltd - Ruby on Rails Plugins Here are some Ruby on Rails plugins we've developed... Let's talk about tests, baby... Some long babbling about test naming heuristics Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  38. 38. Cool! Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  39. 39. When? Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  40. 40. “an object structure contains many classes of objects with differing interfaces, and you want to perform operations on these objects that depend on their concrete classes” Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  41. 41. Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  42. 42. “many distinct and unrelated operations need to be performed on objects in an object structure, and you want to avoid ‘polluting’ their classes with these operations.Visitor lets you keep unrelated operations together by defining them in one class. When the object structure is shared by many applications, use Visitor to put operations in just those applications that need them” Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  43. 43. Show me everything in a consistent manner... ... and send it to my friend via email oh, and send it to her phone as well... and print it..... Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  44. 44. “the classes defining the object structure rarely change, but you often want to define new operations over the structure. Changing the object structure classes requires redefining the interface to all visitors, which is potentially costly. If the object structure classes change often, then it’s probably better to define the operations in those classes” Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  45. 45. Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  46. 46. Consequences Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  47. 47. Visitor makes adding new operations easy Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  48. 48. A visitor gathers related operations and separates unrelated ones Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  49. 49. Adding new ConcreteElement classes is hard Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  50. 50. Visitors can cross object hierarchies Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  51. 51. Visitors can accumulate state Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  52. 52. Visitors may compromise encapsulation Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.
  53. 53. Discussion Copyright Cogent Consulting Pty Ltd (http://www.cogentconsulting.com.au) Licensed under a Creative Commons Attribution-Noncommercial 3.0 License.

×