473,394 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 1489
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
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...
12
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
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
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
by: RedLars | last post by:
Hi, Given this class definition, public class Node { Node parent; object current; ArrayList children;
1
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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...

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.