I'm a lifelong coder but (very) new to OOP and would like to hear some feedback/advice/suggestions on my proposed design structure. I've spent the last week of tinkering with design diagrams. This is very much something I've come up with myself from scratch so I expect there are better ways to do things! Also apologies if I use any incorrect terminology, I'm keen to be corrected and improve on my language usage too.
I am creating a script that needs to:
Get data from various external platforms.
Select other data from my database tables.
Process this data in various ways.
Update the database tables.
Post some data back to the external platforms.
My proposed OOP design is summarised as:
I've also come up with some kind of diagram here if it helps: https://imgur.com/a/c6NdOkG [Note: I should have put interaction arrows between the Message class and Contact class. Such interaction between the models is what provides the fundamental processing for the whole system really.]
Each class performs as follows:
The RequestTool is a simple class that takes some API Request data such as an API key, endpoint and various parameters, then gets or posts to the external platform and returns the response.
The QueryTool is a similar tool but for selecting from, and updating, my database tables.
The ADAPTER class
These provide a transformative function allowing external platform-specific data to be represented as standardised internal objects (MODELs), and conversely for standardised object data to be passed and transformed back to platform-specific endpoints.
There is an adapter subclass for each external platform (e.g. InstaBookAdpater and FaceGramAdapter) and only one instance of each subclass is usually required.
Each adapter object stores its respective API request data in its properties. It uses the RequestTool class to pull data from its respective platform and converts it into standardised MODEL instances. For example, imagine that the InstaBook platform stores messages and contacts in one way, but the FaceGram platform stores messages and contacts in a different way. They also deal with API Requests differently. In my system, each respective adapter gets and transforms these unique data structures into standardised arrays of MessageModel instances and ContactModel instances.
Each adapter can also post data back to its specific platform. So it could be called upon by a MODEL's method (more on these in a moment) once again serving a transformative function. The model could send standardised data to a general sendMessage() adapter method and each adapter subclass would have a tailored sendMessage() method to ensure that the correct message is sent via its specific platform.
The MODEL class
As described above, these are usually first instantiated by an ADAPTER to represent and manipulate data from external platforms in a standardised way. In some cases they may be instantiated from one of my database tables instead.
There are MODEL subclasses for different types of data such as a MessageModel and a ContactModel. The MessageModel might have properties such as "sourcePlatform", "sender" and "messageContent". The ContactModel might have properties such as "platformUsernamePairs", "myNickname" and "isFavourite". ContactModel instances could be instantiated from contact lists on the external platforms, but also from my "Favourite_Contacts" database table too.
Each MODEL subclass uses unique methods to process and respond to data. So the MessageModel might include a searchForHeartEmoji() method and a replyToMessage() method. The MODEL methods do fairly complex things involving their internal properties and the properties of other MODEL objects such as other MessageModel instances and ContactModel instances.
Ultimately the MODELs can send data to the external platforms via the ADAPTERs, update my database to store data permanently, or send alerts to me as the user.
Some examples of data flow
Some ADAPTER-MODEL subsystems only travels "inward". In this case an ADAPTER gets data from an external platform into MODEL instances but never posts anything back. This data could interact "horizontally" with other MODEL instances, or be stored in a database.
Some subsystems work in every direction, getting data from external platforms and out from my database, processing horizontal model-model interactions, and posting back to external platforms and updating my databases.
Some systems work in a more "outward" manner, selecting "historical" records from my database tables to create MODEL instances which then interact with other models or post data to external platforms.
Questions
Does my "adapter-model" design make sense? Does this kind of design have a specific name or are there any similar design patterns? Are there other design patterns that would be more appropriate for my required functionality?
Thank you very much for any guidance you can offer!
Edit: I've just been reading about decorator classes and I think it would make sense to store the relevant adapter instance as an "adapter" property within each model instance. So the adapter instantiates the model like this:
$messageList[] = new Message($this);
And then the model can call its adapter like this:
$this->adapter->sendMessage();