pvinodp
asked on
How to avoid passing this to another class creation?
How to avoid passing "this" to another class creation?
I have classA, classB, classC.
classA::init()
{
Handlers handler[] = { new classB(this) , new classC(this) };
}
In classes classB and classC we do use the passed this value. But how do i remove this?
Is there a common design pattern that overcomes this issue? Is it possible to refactor the class ?
I have classA, classB, classC.
classA::init()
{
Handlers handler[] = { new classB(this) , new classC(this) };
}
In classes classB and classC we do use the passed this value. But how do i remove this?
Is there a common design pattern that overcomes this issue? Is it possible to refactor the class ?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Unless you plan on implementing classA as a singleton, then NO.
ASKER
In that case how would the classA::init() fnction be defined?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks