Inheritance and polymorphism curl tip
Inheritance is one of the best methods to shorten the thousands miles of code and your time in time of developing, it used in many programming languages like PHP, C#, Java , Python and more. This way of coding should be implemented after clear requirements for your application, well planed database, input and output.
I will try to explain why this method of developing is really cool for me and why it could be useful and fun to you too using curl library example. Imagine yourself writing the script that should connect 20 APIproviders using CURL library and to output the data. Someone who is not familiar with Inheritance manner of code writing will create 20 objects for different providers with the same code of curl execution. So where is Inheritance involved in ? If you build this application with using Inheritance method, you should create Parent class for CURL execution, construct function to get instance of curl settings, function to run the curl and to set variables that will handle data that returns on response (protected variables), errors after execution are also stored in protected object variables.
Build the children class and initialize the parent class with curl settings on child class construct function . In child class you should only set the curl options and all the process will be executed in parent class, so you don’t need to type the curl init and curl exec again and again.In children class create functions that will return parent protected variables and here comes polymorphism you can use same child classes functions for different api and parent class will return different response from the api.
It was a rough tip of using inheritance and polymorphism, I will post simple example code later and your life as a coder probably would become painless.
Good luck.
