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 7181037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:28:24+00:00 2026-05-28T17:28:24+00:00

I am new to the design patterns. I have used it on the frameworks

  • 0

I am new to the design patterns. I have used it on the frameworks I’ve used but now I need to choose the right one for what I want to do. My problem is the next:

I have two databases where I need to extract statistics. I’m will be calling it lorem and ipsum. In some cases I need just data from one, from the other or the two combined. Actually I’ve functions like:

  • getAll
  • getAllFromLorem
  • getAllFromLipsum

I think that I can use a factory pattern for do something like this:

<?php
$lorem = Stats::factory('lorem');
$lorem->getAll();

$lipsum = Stats::factory('lipsum');
$lipsum->getAll();

My idea of the structure of this will be have something like:

/stats/lorem.php
/stats/lipsum.php
/stats.php

And when I factory one or other driver it will use the getAll of one of the other file.

I think that this is right. But I also have a problem. I’ll like to have functions that will internally combine it, something like:

<?php
$all = Stats::factory();
$all->getAll(); // this is lorem and ipsum combined (by me, not auto of course...)

But this last thing I don’t know how can I achieve it. Where this getAll function will go?

Can anyone suggest me a good way of doing this?

Thank you in advance!

  • 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-05-28T17:28:25+00:00Added an answer on May 28, 2026 at 5:28 pm

    The idea would be for your Stats::factory() method to return an object of a specific interface. In this case the interface would be something like:

    interface StatsSource {
        function getAll ();
    }
    

    You would have one implementation the “single database” version and another for the combined source version that combined the results. Here’s an naive implementation that simply merges the results together from both sources.

    class SingleDBStatsSource implements StatsSource {
    
        function __construct ($database) {
            // $database would be the name of the db to use
            // or better yet, a connection to the specific db.
        }
    
        function getAll ()
        {
            // use databse connection to retrieve all records.
        }        
    
    }
    
    
    class CombinedStatsSource implements StatsSource {
    
        function __construct ($statsSourceList) {
            $this->statsSourceList = $statsSourceList;
        }
    
        function getAll ()
        {
            $results = array();
            foreach ($this->statsSourceList as $statsSource) {
                $results = array_merge($results, $statsSource->getAll());
            }
            return $results;
        }        
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new in Design Patterns so I have one question about the Builder Pattern.
I'm starting up a new embedded system design using FreeRTOS. My last one used
I have a re-occurring design problem with certain classes which require one-off initialization with
I am new to web-design. I want to set the page-width so that it
I am relatively new to design patterns as they are referred to in a
I'm interested in hearing about design strategies you have used with non-relational nosql databases
Background/Question: I'm fairly new to the singleton design pattern. I've used it once in
is there any new design patterns available other than the patterns covered by GoF
This is a design problem I am facing. Let's say I have a cars
I am new to the MVVM design pattern, and I am working on a

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.