Hello Friends,
I have a problem to integrate new feature in my product, framework team providing us some new APIs and we have to integrate in our application without impacting our old code.
Following is my question:
there is some 3rdParty classes
These classes are provided by 3rdparty component through DLL and these class are not abstract classes and we cannot change 3rdPart code.
1. Class FirstBase
2. Class SecondBase : public FirstBase
3. Class oldFeature : public FirstBase
4. Class NewFeature : public SecondBase
whatever members we were using from OldFeature class, the same member with same name are available in NewFeature class.
Main()
{
oldFeature x1;
x1.doSomething();
}
//New implementation which one I am going to change.
Main()
{
CString ver;
if(ver == "New")
{
NewFeature X1;
}
else
{
oldFeature x1;
}
X1.doSomething();
}
So here I have a problem because there is a thousand places to change the code and I don't want to use If Else condition everywhere.
I have already tried to Google this problem but didn't get proper solution.
I got some solution from C++ object factory and I also tried but My base class is not abstract and returning object is FirstBase which cannot access NewFeature class member.
if I have to check run time type info in Main function then I should go with IfElse condition what I mentioned above.
So I don't want to apply any If-Else in main function, just want to pass version info to get the proper object.
E.g.- something like this:
(C++ object factory example)
Main()
{
Newobject = MyFactory::CreateInstance("New");
Oldobject = MyFactory::CreateInstance("Old");
}
so please provide some solution and let me know if you didn't get my problem
Framed the question in code for better understanding:
class bBase
{
public:
bBase();
~bBase();
virtual void method1() {};
}
class Base : public bBase{
public:
Base();
~Base();
virtual void method2() {};
}
class NewBase : public Base{
public:
NewBase();
~NewBase();
virtual void method3() {};
}
class A : public Base{
public:
A();
~A();
void doSomethingA() {};
void method2() {};
void method1() {};
}
class B : public NewBase{
public:
B();
~B();
void doSomethingB() {};
void method3() {};
void method2() {};
void method1() {};
}
int main()
{
bBase *bB1 = new bBase();
bBase *a1 = new A();
bBase *b1 = new B();
A *a11 = new A();
return 0;
}
Thanks
Saqib