Link to home
Start Free TrialLog in
Avatar of pvinodp
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 ?
SOLUTION
Avatar of Am P
Am P
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Unless you plan on implementing classA as a singleton, then NO.
Avatar of pvinodp
pvinodp

ASKER

In that case how would the classA::init() fnction be defined?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pvinodp

ASKER

thanks