jeudi 7 décembre 2017

need advice for better way of OO Design Patterns [on hold]

I am currently confused as trying to follow SRP that I think my implementation makes it more difficult to change in the future. I have case as follow :

say ClassA, ClassB, ClassC, ClassD, etc that's been instantiated in different controllers. all of those class are dependency Injected with ClassAPI. and ClassAPI is depend on ClassCurl. So currently my code is as follow:

// controller A
$ClassA = new ClassA(new ClassAPI(new ClassCurl));

// controller B
$ClassB = new CLassB(new ClassAPI(new ClassCurl));

// controller C
$ClassC = new ClassC(new ClassAPI(new ClassCurl));

Now the problem is, ClassAPI in the future might be updated so it depends on ClassGuzzle not ClassCurl anymore. When that happened I have to go to each of the controller find all the method that have that injection and replace each of them.

I was thinking instead of ClassAPI is injected with ClassCurl, I can instantiate it in the Class API but it will ended up violating SRP.

What is the better way of doing this? Any OO Design Pattern that I can follow maybe?

Aucun commentaire:

Enregistrer un commentaire