factory

Confusion with interfaces, factories, and inversion of control.

Using interfaces is a very easy way to remove dependencies, but what happens when one of your classes needs a method not defined by the interface? If you're using constructor injection or a factory, how do you access that extra method without casting? Is this possible? Here is an example of a factory with this problem. Am I trying to do...

What is a good PHP design (pattern?) for my testing-application?

I want to write a simple class (PHP5) that can 'run' an unknown amount of subclasses. These subclasses are best translated as 'checks'; they all will more or less do the same thing and give an answer (true / false). Think of it as system startup checks. Over time new checks (subclasses) will be added to a directory and they should autom...

Run code before class instanciation in ActionScript 3

I need to run code in a class declaration before its instanciation. This would be especially useful to automatically register classes in a factory. See: // Main.as public class Main extends Sprite { public function Main() : void { var o : Object = Factory.make(42); } } // Factory.as public class Factory { priva...

Is a "factory" method the right pattern?

Hey all - So I'm working to improve an existing implementation. I have a number of polymorphic classes that are all composed into a higher level container class. The problem I'm dealing with at the moment is that the higher level container class, well, sucks. It looks something like this, which I really don't have a problem with (as th...

ASP.NET MVC based CMS - dynamic generation of form helpers

I am working on an ASP.NET MVC based CMS that presents a rather extreme case. The system must allow the user to add custom content types based on different fields, and for every field, one can add options and validations. The thing is that everything is stored in a complex DB and extracted at runtime using LINQ. I am pretty fresh with A...

Implementing the factory design pattern using metaclasses in python

I found a lot of links on metaclasses, and most of them mention that they are useful for implementing factory methods. Can you show me an example of using metaclasses to implement the design pattern? ...

Python: Class factory using user input as class names

Hi everyone, I want to add class atttributes to a superclass dynamically. Furthermore, I want to create classes that inherit from this superclass dynamically, and the name of those subclasses should depend on user input. There is a superclass "Unit", to which I can add attributes at runtime. This already works. def add_attr (cls, na...

Spring: Using "Lookup method injection" for my ThreadFactory looks not scalable.

Hi, We're building a ThreadFactory so everytime a singleton controller needs a new thread, i get a new instance everytime. Looking at Lookup method injection looks good but what if we have multiple thread classes? I like the fact that i can autowire my threadBeans. like: public abstract class ThreadManager { public abstract T...

Create ObjectPool in Spring

I have a class class ObjPool { MyObject getObject() {...} void returnObject() {...} int getUsedCount() {...} } How can we use Spring framework so that it would provide only one copy of this factory to all (web) applications and so that each and every application use the same ObjPool? I mean if app A gets an object from this ObjPo...

Web scraping: how to get scraper implementation from text link?

I'm building a java web media-scraping application for extracting content from a variety of popular websites: youtube, facebook, rapidshare, and so on. The application will include a search capability to find content urls, but should also allow the user to paste a url into the application if they already where the media is. Youtube Down...

What exactly is a Class Factory?

I see the word thrown around often, and I may have used it myself in code and libraries over time, but I never really got it. In most write-ups I came across, they just went on expecting you to figure it out. What is a Class Factory? Can someone explain the concept? ...

How to write a cctor and op= for a factory class with ptr to abstract member field?

I'm extracting files from zip and rar archives into raw buffers. I created the following to wrap minizip and unrarlib: Archive.hpp - Used to access everything. If I could make all the functions in the other classes inaccessible from the outside, I would. (Actually, I suppose I could friend all the other classes in Archive and use privat...

When should I use a factory to wrap a constructor in Perl?

Why to use factory to wrap a constructor in Perl? An example would help. ...

Create dynamic factory method in PHP (< 5.3)

How would one typically create a dynamic factory method in PHP? By dynamic factory method, I mean a factory method that will autodiscover what objects there are to create, based on some aspect of the given argument. Preferably without registering them first with the factory either. I'm OK with having the possible objects be placed in one...

Activator.CreateInstance vs Factory Pattern

What is the difference between Activator.CreateInstance and factory? Can they be used interchangeably? Or stil do we need a factory pattern? ...

What's the difference between DI and factory patterns?

I have a class which depends on 3 classes, all 3 of which have other classes they rely on. Currently, I'm using a container class to build up all the required classes, inject them into one another and return the application. The simplified version of the container looks something like this: class Builder { private $_options; p...

error: expected constructor, destructor, or type conversion before '(' token

include/TestBullet.h:12: error: expected constructor, destructor, or type conver sion before '(' token I hate C++ error messages... lol ^^ Basically, I'm following what was written in this post to try to create a factory class for bullets so they can be instantiated from a string, which will be parsed from an xml file, because I don't...

How can I configure a Factory with the possible providers?

I have three assemblies: "Framework.DataAccess", "Framework.DataAccess.NHibernateProvider" and "Company.DataAccess". Inside the assembly "Framework.DataAccess", I have my factory (with the wrong implementation of discovery): public class DaoFactory { private static readonly object locker = new object(); private static IWindsorC...

Multiple, Simultaneous Factories and Protocols in Twisted: Same Service, Different Ports

Greetings, Forum. I'm working on a program in Python that uses Twisted to manage networking. The basis of this program is a TCP service that is to listen for connections on multiple ports. However, instead of using one Twisted factory to handle a protocol object for each port, I am trying to use a separate factory for each port. The ...

Implementing a configurable factory

I'm having difficulties finding out how to implement a 'configurable' behavior in a factory class in PHP. I've got at class, which takes another class as an argument in its constructor. The argument class could take a number of arguments in its constructor. An instance of my main class could look something like this $instance = new MyC...