What pattern do I use and how do I implement it for one method that will be handled multiple ways

My scenario: I am creating an application that will allow me to create a mapping of redirect url’s that will point from the request url (the url in the old ecommerce solution) to the target url. There will be multiple implementations as we have multiple ecommerce solutions that were moving to our new one.

I am working in Laravel and have created a controller action that currently returns in JSON the redirect url’s for ONE of our current ecommerce solutions. The implementation of this method is going to differ greatly from one solution to the next.

I could be “dirty” and create an abstract class like storeAbstract and each store extends it and I just look at the store_type sent in to the controller and use the correct class.

This is how I have always done it but I am looking to expand my horizons and have deigned to find a design pattern that fits this situation. If anyone has any suggestions on which design pattern I should use and how I would implement it in laravel it would be greatly appreciated.

Example of how i would do it now:

Abstract class AbstractStore {
    public function getRedirectUrls() {}
}

class StorefrontStore extends AbstractStore {
    public function getRedirectUrls(){
        // code to get the redirect urls
    }
}

class <ecommstore>Store extends AbstractStore {
    public function getRedirectUrls(){
        // code to get the redirect urls
    }
}

This just seems very basic and there has to be a better way.

This is a classic use case for an abstract factory.

You’d have a single interface and then separate concrete factories for each individual implementation. You’d then use factory methods to control the initialization of each set of factories.

2

You can use the strategy pattern to switch essential functionality. This seems to be more about behavior than about creating different kinds of subtypes of one supertype – so the behavioral strategy pattern seems more appropriate to me than the creational Abstract Factory pattern, though they can be combined: Strategy pattern for switching behavior, Abstract Factory pattern for creating the strategies… though you should consider whether such complexity is actually needed.

Using ‘Strategy’ You would have an abstract URLMappingStrategy and concrete strategies assigned to the various e-commerce solutions under a common IURLMappingStrategy-interface. The router then requires the interface and is composed with a concrete implementation (for the respective e-commerce platform), and dispatches calls to a mapURL-method to the concrete strategy it was constructed with (stored by reference in a field of the Router)

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật