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

Related Questions

What does mean AtomicXXX.lazySet(value) method in terms of happens-before edges, used in most of
This has always confused me. It seems like this would be nicer: ["Hello", "world"].join("-")
I am a bit confused why this code compiles. I leave out the necessary
This is not to be confused with How to tell if a DOM element
I usually get so confused with UML and this situation is no different. Let's
I'm confused with how views are organized, and it is important to understand this
I am a little confused here. I would like to do something like this:
This is a bit of a long shot, but if anyone can figure it
This is starting to vex me. I recently decided to clear out my FTP,
This is kinda oddball, but I was poking around with the GNU assembler today

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.