DEV Community

Discussion on: Becoming a better Laravel developer by using the SOLID design principles. Part 2

Collapse
 
abrardev99 profile image
Abrar Ahmad

No. As i explained in article please check, you don't need to change controller now. You need to add an other payment class and implement payableInterface. Then in payment class add if else type check and return appropriate class. Done

Collapse
 
connor11528 profile image
Connor Leech

Instead of using if-else there could be an array on the PaymentFactory class where the type maps to the class, like 'credit' => 'CreditCardPayment' and then instantiate the correct class based on the type. Definitely an opportunity for improvement by using constants here. That if-else is not so bueno imho. Thanks for the article! Looking forward to the rest :)

Thread Thread
 
abrardev99 profile image
Abrar Ahmad

Yes we can use this approach. As my examples are not perfect. There is a plenty of room for improvements.