Bill, At first glance it seems like you are not using the strategy pattern because the little bit of code you provide matches exactly what the GoF book says the strategy pattern is supposed to eliminate (see the top of page 318).
Hopefully where you have '// Use Strategy X' you are instantiating a particular strategy object and then using that instance when you instantiate your context object. If you are not doing that then you are not really using the strategy pattern. Assuming you are though, I would recommend a factory that would have a method that takes the value you are currently switching on and returns an instance of a strategy object. If new source values can be added often then I would drive the factory logic with an XML file that matched source values to qualified class names of concrete strategy objects. That way when new sources come along all you need to do is write a new concrete strategy class and add an association in the XML file. No other code would need to be touched. Russ -----Original Message----- From: Unmoderated discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Bill Bassler Sent: Friday, March 25, 2005 10:07 AM To: [email protected] Subject: [ADVANCED-DOTNET] Most appropriate design pattern to use for ... I'm trying to determine the most appropriate design pattern to implement for the following problem. I'm receiving an xml document whose structure contains an element defining a source. Each source's document contains a similar but distinct xml document. Each one of the distinct documents requires a distinct set of message processing steps. I have implemented the document specific processing steps/algorithm using the Strategy pattern. This works well at cleanly encapsulating the processing logic. The issue I'm trying to solve is - What's the most appropriate/cleanest way to inspect the source element in order to route the xml message to the appropriate Strategy for processing. Currently I use a switch statement to decide the processing. e.g. switch (enrollmentDoc.SelectSingleNod("/EnrollForm/Source").InnerXml.ToUpper ()) { case 1: // Use Strategy 1 case 2: // Use Strategy 2 } This works, but I'm looking for something a little less clunky and hopefully more modular. I've looked at the Command pattern ... which seems to somewhat fit the task. Possibly the Chain of Command but I don't know that I need that level of processing flexiblity as what I need to do can be encapsulated pretty well in the Strategy. =================================== This list is hosted by DevelopMentor(r) http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentor� http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com
