Visitor and Stratergy Pattern

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • C#

    Visitor and Stratergy Pattern

    Dear Freinds,

    I was going through Stratergy and Visitor patterns. I am really
    confused. Both look same passing the logic object in to the a business
    object and the logic object works on the business object.

    Please clarify.

    Regards,
    Design Pattern Learner

  • Peter Morris

    #2
    Re: Visitor and Stratergy Pattern

    StrategyPattern is a way of saying you want something done in a flexible
    way. For example a package transport company might charge its customers a
    basic rate based on size and weight of the package, but for larger and more
    regular customers they may have a different approach completely that
    requires custom code.

    A visitor pattern is something else completely. If you often find yourself
    writing code like this on the same structure....

    foreach (CustomerSite site in Customer.Sites)
    foreach (VendingLocatio n location in site.VendingLoc ations)
    foreach (VendingMachine machine in location.Vendin gMachines)

    Then you might want to consider using a VisitorPattern. The pattern
    basically does the looping for you and executes a method for each item. The
    benefit being that if ever you add a new level to the loop you would then
    add a new method to the callback interface, the compile will then fail
    everywhere you haven't handled the new loop level because the called back
    class has not implemented the method.

    The visitor pattern is also useful when some of your members are private.


    Pete

    Comment

    • JackPot

      #3
      Re: Visitor and Stratergy Pattern

      Hey Peter, are you going to get a cut of the $120 this dude is demanding for
      his video series he is building using guys like you to teach him free what
      he is putting into his product and selling?

      I'm certainly a business-minded developer myself and I've developed revenue
      share services and would at the very least give named attribution to those
      who have mentored me as I learn so I was just wondering...


      "Peter Morris" <mrpmorrisNO@SP AMgmail.comwrot e in message
      news:OIZZ$uy8IH A.2332@TK2MSFTN GP03.phx.gbl...
      StrategyPattern is a way of saying you want something done in a flexible
      way. For example a package transport company might charge its customers a
      basic rate based on size and weight of the package, but for larger and
      more regular customers they may have a different approach completely that
      requires custom code.
      >
      A visitor pattern is something else completely. If you often find
      yourself writing code like this on the same structure....
      >
      foreach (CustomerSite site in Customer.Sites)
      foreach (VendingLocatio n location in site.VendingLoc ations)
      foreach (VendingMachine machine in location.Vendin gMachines)
      >
      Then you might want to consider using a VisitorPattern. The pattern
      basically does the looping for you and executes a method for each item.
      The benefit being that if ever you add a new level to the loop you would
      then add a new method to the callback interface, the compile will then
      fail everywhere you haven't handled the new loop level because the called
      back class has not implemented the method.
      >
      The visitor pattern is also useful when some of your members are private.
      >
      >
      Pete

      Comment

      • Peter Morris

        #4
        Re: Visitor and Stratergy Pattern

        Hey Peter, are you going to get a cut of the $120 this dude is demanding
        for his video series he is building using guys like you to teach him free
        what he is putting into his product and selling?
        >
        I'm certainly a business-minded developer myself and I've developed
        revenue share services and would at the very least give named attribution
        to those who have mentored me as I learn so I was just wondering...
        I didn't follow the link at the bottom of the post. I assumed it was the
        site he couldn't understand but it seems you are correct. In honest I am
        not sure how to feel about it, probably everyone here makes money out of the
        information they pick up in some way or another.



        Pete

        Comment

        Working...