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

  • Home
  • SEARCH
  • 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 7506725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:20:22+00:00 2026-05-29T22:20:22+00:00

Isn’t factory a general singleton? Or may the Factory pattern be Singleton sometimes? Let’s

  • 0

Isn’t factory a general singleton? Or may the Factory pattern be Singleton sometimes?
Let’s assume we have the following Factory pattern class:

abstract class Factory {

    /* This cache contains objects that has already been called.
    ** It stores the class name, arguments and the object itself.
    ** If an another call for the same class with the same arguments 
    ** is made we return the object.
    */ 
    private static $cache;

    public static function __callStatic($class, $args) {
        // 1) we check if the class already exists in the cache

            // 2) if it does then we return the object in the cache

            // 3.1) otherwise we create a new object
            // 3.2) we pass to the constructor of that object the arguments with ReflectionClass
            // 3.3) we store the class name, arguments and object in the cache
    }

}

And a concrete class

class My extends Factory {}

And let’s assume we have a class DontKnow($arg1, $arg2) that accept arguments $arg1 and $arg2 to the constructor. And let’s assume we have another class DoNot() that doesn’t accept any parameter to the constructor.

Now when we call

My::DontKnow('sample', 3);

we return an object that is now stored inside the cache of our factory class.
If we call it again our factory class will not instantiate a new object, but will use the same again.

So for example if we set My::DontKnow('sample', 3)->setSomething('key', 'myvalue'); and inside another scope we call My::DontKnow('sample', 3)->getSomething('key'); it will print myvalue.

But if we call My::DoNot() the factory class will return a “singleton” object of the class DoNot() that, since our factory class My is static, has static scope and can be, then, called everywhere.

Isn’t this another example of Singleton? Is this to avoid as well as the Singleton pattern?

  • 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-29T22:20:24+00:00Added an answer on May 29, 2026 at 10:20 pm

    No, it isn’t. What you are describing would be a special use case of the factory pattern or not a factory at all. A simple factory doesn’t do ‘instance management’, it just returns a new instance of the needed concrete subclass.

    The fact that the factory method itself is static, doesn’t mean that the methods of the returned subclass are. A factory, as the name says it, produces concrete objects with non-static functionality.

    http://sourcemaking.com/design_patterns/factory_method

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

Sidebar

Related Questions

This isn't legal: public class MyBaseClass { public MyBaseClass() {} public MyBaseClass(object arg) {}
Isn't there a Design Pattern who describes how to high cohesion? I need some
Isn't A a = new A(); // A is a class name supposed to
Isn't visual studio supposed to automatically generate this file for each webservice creation ?
This isn't a holy war, this isn't a question of which is better. What
Why isn't Collection.remove(Object o) generic? Seems like Collection<E> could have boolean remove(E o); Then,
Isn't there some way to re-write the following code, such that I don't need
Isn't every language compiled into low-level computer language? If so, shouldn't all languages have
Isn't there a better way to accomplish this?: (RegionID is a Flex ComboBox) RegionID.selectedItem=value.Region;
Why isn't this working? <ajaxToolkit:TabPanel Enabled='<%# User.IsInRole(admin) %>'... While this works: <asp:TextBox Enabled='<%# User.IsInRole(admin)

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.