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 3437272
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:02:41+00:00 2026-05-18T08:02:41+00:00

i hope you can help me with my problem: I have a Class doing

  • 0

i hope you can help me with my problem:

I have a Class doing soap calls. But if the soap definition changes i’ll have to write a new class or inherit from it etc.
So I came to the solution to write something like that:

switch(version)
{
  case "1.0":
     saopV1.getData()
  case "2.0":
     soapV2.getData()
}

Well pretty bad code, i know. Then I read about the Strategy pattern and i thought, wow that’s what i need to get rid of this bad switch-case thing:

abstract SoapVersion
{
    public SoapVersion GetSoapVersion(string version)
    {
         //Damn switch-case thing
         //with return new SoapV1() and return new SoapV2()
    }
    public string[] virtual getData()
    {
          //Basic Implementation
    }
}

class SoapV1:SoapVersion
{
       public override string[] getData()
       {
           //Detail Implementation
       }
}

class SoapV2:SoapVersion
{//the same like soapv1}

But i can’t avoid using “ifs” or switch cases in my code. Is this possible using OO-techniques??

Edit:
The GetSoapVersion-Function should be static

  • 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-18T08:02:42+00:00Added an answer on May 18, 2026 at 8:02 am

    That’s more or less the right way to do this in a beautiful fashion.
    At some point in your code, you’ll have to make a decision whether v1 or v2 has to be used, so you’ll have to have a conditional statement (if or switch) anyway. However, when using a strategy and a factory (factory method or factory class), you’ve centralized that decision.

    I would make my factory method on the abstract class static though.
    Also, I would make use of the template-method pattern: that is, a public, non overridable GetData method which calls a protected virtual (abstract) method that should be overriden in a concrete implementation.

    public abstract class SoapProcessor
    {
    
        protected SoapProcessor() { /* protected constructor since public is of no use */  }
    
        public static SoapProcessor Create( SoapVersion version )
        {
              switch( version )
              {
                   case SoapVersion.Version1 : return new SoapV1Processor();
                   case SoapVersion.Version2 : return new SoapV2Processor();
                   default: throw new NOtSupportedException();
              }
        }
    
    
        public string[] GetData()
        {
             return GetDataCore();
        }
    
        protected abstract GetDataCore();
     }
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My question really has three related parts which I hope you can help me
I hope there's a SharePoint expert here on SO who can help with this.
I hope someone can guide me as I'm stuck... I need to write an
I hope I can explain this clearly enough. I have my main form (A)
Hope anyone can shed light on this so I can use pens with dash
this is my first question here so I hope I can articulate it well
Originaly posted a while back on a different forum, hope I can find a
This really, really urks me, so I hope that someone can give me a
I hope this question does not come off as broad as it may seem
I hope everyone will pardon the length, and narrative fashion, of this question. I

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.