Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What design pattern would be best to allow one common class from multiple providers?

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?

like image 756
Martin Bean Avatar asked Aug 30 '11 09:08

Martin Bean


People also ask

What are the 3 common design patterns groups?

Design Patterns are categorized mainly into three categories: Creational Design Pattern, Structural Design Pattern, and Behavioral Design Pattern.

Which design pattern provides a single class which provides?

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.

Which design pattern should you use when a class wants?

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.

Which design pattern is the most appropriate?

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.


1 Answers

I'd go with something like this:

enter image description here

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.

like image 122
kstaruch Avatar answered Nov 15 '22 08:11

kstaruch