Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9250731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:31:03+00:00 2026-06-18T10:31:03+00:00

I’m designing an application that has a general code base, but some parts of

  • 0

I’m designing an application that has a general code base, but some parts of it are very specific to certain shopping carts. As the # of carts its designed to accommodate grows, the more methods I find myself adding to the main class. This is making the class rather large and unwieldy.

How can I modularize things so that each specific cart that loads the main class has its own specific methods that are only loaded if the cart make and version match?

For instance, suppose I have things setup in this manner right now:

class Thingy {
    public function doStuffMagento16() {...}
    public function getMoreMagento16() {...}
    public function doStuffOpencart15() {...}
    public function getMoreOpencart15() {...}
    public function doStuffPrestashop12() {...}
    public function getMorePrestashop12() {...}
    public function doStuffXcart45() {...}
    public function getMoreXcart45() {...}
}

How would I make it look more like this, such that methods just overload the defaults in the main class:

class Thingy {
    public function doStuff() {...}
    public function getMore() {...}
}

I’m really thinking I need to create child classes to do this that extend the main class and just autoload them when the main interface is called, but I want to make sure this is really the most efficient and easily maintainable option before I try that….or if I should go another direction.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:31:04+00:00Added an answer on June 18, 2026 at 10:31 am

    This calls for the adapter pattern; you adapt specific cart interfaces to a generic interface.

    Trivial example:

    /* existing cart implementation */
    class CartFromVendorX
    {
        public function addProduct( CartXProduct $product ) {}
    }
    
    /* existing cart implementation */
    class CartFromVendorY
    {
        public function pushProduct( CartYProduct $product ) {}
    }
    
    /* generic cart interface */
    interface CartAdapterInterface
    {
        public function addItem( $item );
    }
    
    class CartAdapterVendorX
        implements CartAdapterInterface
    {
        protected $adaptee;
    
        public function __construct( CartFromVendorX $adaptee )
        {
            $this->adaptee = $adaptee;
        }
    
        public function addItem( $item )
        {
            /* transfrom generic $item to CartXProduct, for instance */
    
            $this->adaptee->addProduct( $product );
        }
    }
    
    class CartAdapterVendorY
        implements CartAdapterInterface
    {
        protected $adaptee;
    
        public function __construct( CartFromVendorY $adaptee )
        {
            $this->adaptee = $adaptee;
        }
    
        public function addItem( $item )
        {
            /* transfrom generic $item to CartYProduct, for instance */
    
            $this->adaptee->pushProduct( $product );
        }
    }
    

    Then a generic cart consuming client:

    class CartClient
    {
        protected $cart;
    
        public function __construct( CartAdapterInterface $cart )
        {
            $this->cart = $cart;
        }
    
        /* rest of implementation that acts on CartAdapterInterface instance */
    }
    

    Usage:

    $cartAdapter = new CartAdapterVendorX( new CartFromVendorX() );
    $client = new CartClient( $cartAdapter );
    

    P.S.: you don’t necessarily have to implement the adapters such that you pass the original implementations to their constructors. Something like this could work as well:

    class CartAdapterVendorX
        implements CartAdapterInterface
    {
        protected $adaptee;
    
        public function __construct()
        {
            $this->adaptee = new CartFromVendorX();
        }
    
        public function addItem( $item )
        {
            /* perhaps transfrom generic $item first */
    
            $this->adaptee->addProduct( $item );
        }
    }
    

    Then its usage would simplify to:

    $cartAdapter = new CartAdapterVendorX();
    $client = new CartClient( $cartAdapter );
    

    You can vary on the actual implementation details, but this should give you a general idea. For instance, there’s a big chance you end up implementing a façade pattern, for some or all original carts, along with it as well, because you may want to wrap multiple method calls to one original implementation into a single method of the adapter interface.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.