Reputation: 196
I am learning about design patterns. Currently I am working on a web service and I have time to structure the code, where I want to implement some design patterns.I already do watch to have each class doing one related thing, and write small functions with one or two parameters, but when it comes to design patterns, I am stuck.
My application is getting the data from external api, users, organizations and jobs. I have created these three classes, and currently they are all containing almost same curl call, same curl options and headers. And each of this class have one function, for organizations - getOrganizations, for users - getUsers ... Which all have same body, just a different curl call.
So I need just a reference, to a design patterns that can help me structure maintainable code.
Upvotes: 0
Views: 50
Reputation: 121
From reading your description you just need to practice OOP a bit more. (object oriented programming).
In this given example you could make a function that accepts the URL and either make all your requests extend from that base class that has that function 9r make a utility class with the curl logic and simply use that.
Also there are a ton of good php curl plugins on composer which can help you.
Upvotes: 2