473,480 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Visitor and Stratergy Pattern

C#
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
http://www.questpond.com/FreeDesign1.htm
Jul 31 '08 #1
3 1188
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 (VendingLocation location in site.VendingLocations)
foreach (VendingMachine machine in location.VendingMachines)

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

Jul 31 '08 #2
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" <mr*********@SPAMgmail.comwrote in message
news:OI**************@TK2MSFTNGP03.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 (VendingLocation location in site.VendingLocations)
foreach (VendingMachine machine in location.VendingMachines)

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
Jul 31 '08 #3
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

Aug 1 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2343
by: Wavemaker | last post by:
I've been playing with C# v2.0 today, and having quite a bit of fun. The new version has added iterators. The iterators are coded directly into the class to be iterated. For example: public...
2
1471
by: Imre Palik | last post by:
Hi, I am trying to create a framework, that automatically generates a base class for the visitor pattern: template <typename param, typename ret = void> struct visitor { typedef ret...
12
3006
by: FluffyCat | last post by:
New on November 28, 2005 for www.FluffyCat.com PHP 5 Design Pattern Examples - the Visitor Pattern. In the Visitor pattern, one class calls a function in another class and passes an instance of...
17
2579
by: Merlin | last post by:
Probably there is no right or wrong answer to this but I thought to ask to put my mind at rest. Ok lets say you have a object hierarchy (eg. the Glyph in Lexi from GOF book) and you want to use the...
0
1894
by: Siphiuel | last post by:
Hi everyone. When using visitor pattern, we have a nasty dependence on the types of visitable objects that is coded way on top on the visitor hierarchy. i mean, like this: class AbstractVisitor...
1
2359
by: RedLars | last post by:
Hi, Given this class definition, public class Node { Node parent; object current; ArrayList children;
1
6486
by: JosAH | last post by:
Greetings, this week we let go of all that algebraic stuff and concentrate a bit more on what object oriented programming is all about. Java claims to support OO, so why not use it? In this...
0
11591
weaknessforcats
by: weaknessforcats | last post by:
Design Patterns: Visitor Introduction Polymorphism requires a class hierarchy where the interface to the hierarchy is in the base class. Virtual functions allow derived classes to override base...
3
1493
by: C# | last post by:
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...
3
2291
by: aaragon | last post by:
Hello everyone, I've been trying to work with the visitor design pattern, and it works fine except for the following. Let's suppose that we have a fixed hierarchy of classes (many of them)...
0
7037
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7034
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7076
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
6886
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4768
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4472
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2990
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.