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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:26:41+00:00 2026-06-17T11:26:41+00:00

A factory class isn’t the end product I am looking for but it is

  • 0

A factory class isn’t the end product I am looking for but it is basically my problem boiled down. I am looking for a class we’ll call foo that can be passed in another class bar as a parameter to its constructor such that when later calling fooInstance.create() it returns a new instance of bar. I can easily figure out how to make a fooInstance.create(bar) create an instance of bar. But that isn’t what I need. I need each instance of the factory class to create a specific type of object. so:

    fooCar = new foo(Car);
    fooTruck = new foo(Truck);
    myCar = fooCar.create();
    myTruck = fooTruck.create();

This would be something easily handled by Generics in c#. I either get errors or I end up screwing with the prototype of foo which then changes the type created by all instances of foo.

  • 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-17T11:26:42+00:00Added an answer on June 17, 2026 at 11:26 am

    Just return a regular object from your factory, with just one create method:

    function foo (Constructor) {
        return {
            create: function () {
                return new Constructor();
            }
        };
    }
    

    Check out the fiddle: http://jsfiddle.net/fR5Gz/1/

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

Sidebar

Related Questions

I have a factory class, DocumentLoaderFactory , which simply returns an instance that implements
I'm writing a factory class that should be able to return singleton instances of
I'm trying to test a class that takes a factory ( Func<T> ) and
I have a class that takes in a db factory. public class ArticleManager {
I have a Generic Class Factory class that has two methods one utilizes the
Consider a theoretical factory class containing over a thousand of attributes (models, by example,
So I have a factory class and I'm trying to work out what the
I have the following factory class: public class MessagePresenterCreator implements IPresenterFactory{ @Override public MessagePresenter
In my console application have an abstract Factory class Listener which contains code for
Retrieving the COM class factory for component with CLSID {B4E1B2EC-151B-11D2-926A-006008123235} failed due to the

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.