What are DI and IOC? If you say DI-Dependency Injection, IOC-Inversion of control you are right but wait “There is a difference between knowing the name of something and knowing something”.
In the above code, ChargeBee clas s uses the ChargeBeeSubscription class,which means if you want to create the ChargeBee object we need ChargeBeeSubscription Object.
We are injecting the ChargeBeeSubscription object to the ChargeBee constructor and the ChargeBee object to PaymentGateWay constructor.
Having control in multiple places or having control in a single place, which is easy to manage.