Hope you can help me with my problem:
I have a class making soap calls. But if changing the definition of soap, I will need to write a new class or inherit it, etc. So I came to the decision to write something like this:
switch(version)
{
case "1.0":
saopV1.getData()
case "2.0":
soapV2.getData()
}
Well, very bad code, I know. Then I read about the Strategy template, and I thought, wow, that I need to get rid of this bad thing with switching:
abstract SoapVersion
{
public SoapVersion GetSoapVersion(string version)
{
}
public string[] virtual getData()
{
}
}
class SoapV1:SoapVersion
{
public override string[] getData()
{
}
}
class SoapV2:SoapVersion
{
But I cannot avoid using "ifs" or switching cases in my code. Is this possible using OO methods?
Edit: The GetSoapVersion function must be static.
source
share