I'm looking to write an application. Think e-commerce. But think, an e-commerce site that is powered by another provider.
The scenario would be thus: I would white-label an e-commerce site front that's powered by a client's existing e-commerce platform, whether this be Magento, CubeCart, Prestashop, or so on.
These platforms are all going to have their own naming conventions and whatnot, and I want a common interface within my app. For example:
class Product {
var $title;
var $price;
var $image;
var $description;
// and so on
}
Obviously different providers may call things differently. For example, title
may be product_title
in a provider, or product_name
, or productTitle
, and so on. Another example: price
may be cost
, or unit_price
, and so on. Hopefully the problem becomes apparent.
Ideally, I'd like to be pointed to the best design pattern to abstract a service from my app's business classes, so I can add providers without having to re-factor anything in my app down the line.
What design pattern would be the best for the above scenario?
Design Patterns are categorized mainly into three categories: Creational Design Pattern, Structural Design Pattern, and Behavioral Design Pattern.
Explanation: Singleton pattern involves a single class which is responsible to create an object while making sure that only one object gets created. This class provides a way to access the only object which can be accessed directly without need to instantiate another object of the same class.
The Factory Method pattern is generally used in the following situations: A class cannot anticipate the type of objects it needs to create beforehand. A class requires its subclasses to specify the objects it creates. You want to localize the logic to instantiate a complex object.
Factory Design Pattern One of the most popular design patterns used by software developers is a factory method. It is a creational pattern that helps create an object without the user getting exposed to creational logic. The only problem with a factory method is it relies on the concrete component.
I'd go with something like this:
Depending on the providers you want to integrate with, you may want to add additional Decorators or Facades (for example to simplify API) between Adapters and actual providers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With