473,800 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
+ 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 1513
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

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*********@SP AMgmail.comwrot e in message
news:OI******** ******@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
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
2359
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 IEnumerable<int> Visit(SomeVisitor visitor) { int position = 0; for(int i = 0; i < Count; i++) {
12
3042
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 itself. The called class has special functions for each class that can call it. With the visitor pattern, the calling class can have new operations added without being changed itself.
17
2610
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 visitor pattern. So we place an accept method in the the base class glyph and procede to create the visitor hierarchy. The accept signature will look like this void Glyph::Accept(Visitor& v); The Visitor hierarchy will have a Vistor base...
0
1919
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 { public: virtual void visit(Object_type_1 *); virtual void visit(Object_type_2 *)
1
2373
by: RedLars | last post by:
Hi, Given this class definition, public class Node { Node parent; object current; ArrayList children;
1
6530
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 week's article we're going to talk a bit about when and why to apply certain patterns. We'll start with the Visitor pattern. The pattern is also named 'double dispatch' which will become clear near the end of this little article. Here's the...
0
11630
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 class functions. Applications using polymorphism typically have functions with base class pointers or references as arguments. Then derived objects are created and used as arguments to these functions. Inside the function, only the base class methods...
3
1206
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 business object. Please clarify. Regards, Design Pattern Learner
3
2315
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) which I cannot modify. I decided to use the visitor design pattern depending on the actual type of the classes because those classes already support the loki visitor. #include <Loki/Visitor.h>
0
9690
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10505
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9085
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5471
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.