I've been refactoring some of my procedural code to OOP, and I'm wondering if using the adapter pattern is overkill in this case.
Basically, I created a Order
class. All class properties are a field in the database:
class Order {
private ?int $id = null;
private float $value;
private string $date;
private string $time;
...
}
These orders are sent by third party APIs, and each API has it's own JSON format. For example the date
property, one of the APIs might give me creation_date
as the field name, other might send just date
, or datetime
, etc.
I have a HTTP endpoint on my end for each third party. Each third party have a panel/dashboard in which I specify the endpoint. Whenever an order comes up on their end, they automatically send it to me through the endpoint I specified!
Initially, I've been thinking about doing something like this inside the Order
class:
public static function create_from_thirdparty_one( $api_data ){
$instance = new Order();
...
return $instance;
}
public static function create_from_thirdparty_two( $api_data ){
$instance = new Order();
...
return $instance;
}
But as I integrate with more APIs, this seems.. I don't know, awkward?
So, I though about using the Adapter pattern! But since I'm not familiar with desing patterns, as this is my first time working with one, I though about asking you guys, so.. what you guys think? Is this an acceptable use case?
Thank you!
Order
objects from the third party specific code.