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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:14:54+00:00 2026-05-13T11:14:54+00:00

This confuses me, in the most simplest terms what does it do? Pretend you

  • 0

This confuses me, in the most simplest terms what does it do? Pretend you are explaining to your mother or someone almost please.

  • 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-13T11:14:54+00:00Added an answer on May 13, 2026 at 11:14 am

    A factory creates an object. So, if you wanted to build

     class A{
        public $classb;
        public $classc;
        public function __construct($classb, $classc)
        {
             $this->classb = $classb;
             $this->classc = $classc;
        }
      }
    

    You wouldn’t want to rely on having to do the following code everytime you create the object

    $obj = new ClassA(new ClassB, new Class C);
    

    That is where the factory would come in. We define a factory to take care of that for us:

    class Factory{
        public function build()
        {
            $classc = $this->buildC();
            $classb = $this->buildB();
            return $this->buildA($classb, $classc);
    
        }
    
        public function buildA($classb, $classc)
        {
            return new ClassA($classb, $classc);
        }
    
        public function buildB()
        {
            return new ClassB;
        }
    
        public function buildC()
        {
            return new ClassC;
        }
    }
    

    Now all we have to do is

    $factory = new Factory;
    $obj     = $factory->build();
    

    The real advantage is when you want to change the class. Lets say we wanted to pass in a different ClassC:

    class Factory_New extends Factory{
        public function buildC(){
            return new ClassD;
        }
    }
    

    or a new ClassB:

    class Factory_New2 extends Factory{
        public function buildB(){
            return new ClassE;
        }
    }
    

    Now we can use inheritance to easily modify how the class is created, to put in a different set of classes.

    A good example might be this user class:

    class User{
        public $data;
        public function __construct($data)
        {
            $this->data = $data;
        }
    }
    

    In this class $data is the class we use to store our data. Now for this class, lets say we use a Session to store our data. The factory would look like this:

    class Factory{
        public function build()
        {
            $data = $this->buildData();
            return $this->buildUser($data);
        }
    
        public function buildData()
        {
            return SessionObject();
        }
    
        public function buildUser($data)
        {
            return User($data);
        }
    }
    

    Now, lets say instead we want to store all of our data in the database, it is really simple to change it:

    class Factory_New extends Factory{
        public function buildData()
        {
            return DatabaseObject();
        }
    }
    

    Factories are a design pattern we use to control how we put objects together, and using correct factory patterns allows us to create the customized objects we need.

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

Sidebar

Ask A Question

Stats

  • Questions 284k
  • Answers 284k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer use this to include: http://api.drupal.org/api/function/module_load_include/6 May 13, 2026 at 4:34 pm
  • Editorial Team
    Editorial Team added an answer After poking around a bit through the Introduction to Tkinter,… May 13, 2026 at 4:34 pm
  • Editorial Team
    Editorial Team added an answer In order to split by a string you'll have to… May 13, 2026 at 4:34 pm

Related Questions

I find the nature of this question to be quite suited for the practical-minded
I am having some threading issues with a large app I am working on
I'm a Sql Server Service Broker novice and I'm trying to grasp the best
I've recently started to learn C++ and am completely confused with the choices of
I have an MS Access 2003 database that I'm using to develop a basic

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.