Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3948882
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:25:38+00:00 2026-05-20T01:25:38+00:00

I have a lot of methods (in this case, from web services, but maybe

  • 0

I have a lot of methods (in this case, from web services, but maybe this has no impact?) to call. They’re already fixed release versions and won’t be changed, it’s up to me to adapt to them. I already have the proxies on my project, and in fact, I already call them and the project is ok.

This class main method gets some input parameters (transaction type, and a XML string containing the transaction data). Based on TransactionType, I know which class and method I should call. I also must provide it with a type variable it expects, already built from the provided XML. Here’s how it is today (I don’t have the code right here, so pardon me for any syntax errors), approximately:

public class MyClass ()
{
  public void MyMethod( string TransactionType, string XML )
  {
    switch( TransactionType ) {
       case "1":
         type1VO type1Object = ( new Deserializer<Type1>() ).XML2Object( XML );
         ws = new WSProxy1();
         string response = ws.Method1( type1VO );
         //
         // lots of other lines of code that use type1VO, type1Object, the response, etc.
         //
         break;
       case "2":
         type2VO type2Object = ( new Deserializer<Type2>() ).XML2Object( XML );
         ws = new WSProxy2();
         string response = ws.Method2( type2VO );
         //
         // same structure here, but handling types specific for "case 2"
         //
         break;
    }
    ...
  }
}

And it goes on and on. Today, this code is already working, handling about 15 different transaction types, but it was developed in the way you see above. As I’m about to change it (will move this code to a library of itself, ’cause other systems need this logic), I thought it could benefit from some code refinement. Also, the above code is pretty reduced: there are more lines that handle the specific types for each case, I just gave an example.

As it’s working, I’m not so worried, but it doesn’t seem so “elegant” to me. Gives me the impression that some kind of design pattern could handle this, and that I could handle any transaction with a single block, instead of repeating it for every transaction type. Maybe I’m wrong and this can’t be done, I just “felt” it could by looking at the repeating code.

It’s C# on .NET v2.0, but I don’t mind if there are answers involving other versions or languages. I care much more about the involved concept. I thank you all for any hints you could provide, they’re all always great.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T01:25:39+00:00Added an answer on May 20, 2026 at 1:25 am

    You can try a combination of the Adapter Pattern and Strategy Pattern.

    Create an interface for calling the method and write adapters for each of your proxies that support this interface. The adapters should encapsulate any behavior that is specific to the object it is adapting. You can also have the interface return the transaction type that they support to enable switching at runtime.

    An example might be:

    public interface IExecuteStrategy
    {
        string TransactionType {get;}
        void Execute( string xmlData );
    }
    
    public class WsProxy1Adapter : IExecuteStrategy
    {
        public string TransactionType
        {
            get { return "1"; }
        }
    
        public void Execute(string xmlData)
        {
            Type1 type1Object = ( new Deserializer<Type1>() ).XML2Object( XML );
            var ws = new WSProxy1();
            string response = ws.Method1( type1Object );
            //
            // lots of other lines of code that use type1VO, type1Object, the response, etc.
            //
        }
    }
    
    public class WsProxy2Adapter : IExecuteStrategy
    {
        public string TransactionType
        {
            get { return "2"; }
        }
    
        public void Execute(string xmlData)
        {
            Type2 type2Object = ( new Deserializer<Type2>() ).XML2Object( XML );
            var ws = new WSProxy2();
            string response = ws.Method1( type2Object );
            //
            // lots of other lines of code that use type1VO, type1Object, the response, etc.
            //
        }
    }
    
    public class MyClass
    {
        private static Dictionary<string, IExecuteStrategy> _transactionHandlers;
    
        static MyClass()
        {
            _transactionHandlers = new Dictionary<string,IExecuteStrategy>();
    
            IExecuteStrategy obj = new WsProxy1Adapter();
            _transactionHandlers.Add(obj.TransactionType, obj);
    
            obj = new WsProxy2Adapter();
            _transactionHandlers.Add(obj.TransactionType, obj);
        }
    
    
        public void MyMethod( string TransactionType, string XML )
        {
            _transactionHandlers[TransactionType].Execute( XML );
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a similiar class with a lot of methods, but getData() only returns
I have lot of code in my Tornado app which looks like this: @tornado.web.asynchronous
I am designing an API. It will have a lot of methods which do
I have a webservice and initiate a lot of methods in the constructor. I
i have seen a lot of screencasts where the author is creating methods with
We have lot of object with this kind of design : Interface and several
I have created a JavaScript application that has a lot of array manipulations (sorting,
I'm fairly new to jquery/jqueryui, but I'm progressing fast. I have a lot of
I have been reading a lot about this - I feel like I'm very
I'm always referencing DLLs in my C# code, but they have remained somewhat of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.