factory

Using base class constructor as factory in Python?

I'm using base class constructor as factory and changing class in this constructor/factory to select appropriate class -- is this approach is good python practice or there are more elegant ways? I've tried to read help about metaclasses but without big success. Here example of what I'm doing. class Project(object): "Base class and ...

Implementing a Factory that uses Specifications to determine which type of object to create

This is mainly a thought experiment. So this all is sample code. My goal was to use the specification pattern to eliminate giant blocks of conditional code inside a factory. So with this sample I have a StatusData object that I want to get an implementation of IStatusUpdate that is appropriate for for it. I have the following set of tes...

What is the advantage to have all my classes instantiated only through the Factory DP?

What is the advantage to have all my classes instantiated only through the Factory DP? As far as know a Factory is good when you have to choose from a list of similar objects to perform some task,let's say like translations classes (english-> franch, arab->hebrew ...) But when you have really one possible option, no reason to obscure/ab...

In NHibernate, can I use factory to build complex aggregate object (Entity)?

In NHibernate, can I use factory to build complex aggregate object (Entity)? If yes then how? If not.. then what is your approach? ...

C++: Is there a way to instantiate objects from a string holding their class name?

Hi guys, I have a file: Base.h class Base; class DerivedA : public Base; class DerivedB : public Base; /*etc...*/ and another file: BaseFactory.h #include "Base.h" class BaseFactory { public: BaseFactory(const string }; Base * Create() { if(msClassName == "DerivedA") { return new DerivedA(); } else i...

Factory pattern

I've been trying to create a factory (in Java) that prohibits subclassing of the factory product and prevents the concrete factories from being used by anyone except the abstract factory. What do you think of this... class Client { public static void main(String[] args) { Animal animal = Animal.create(Lion.class); ...

Problem with non activerecord associations in factory girl

I just started to use factory girl to replace fixtures when I am testing. I am working on a twitter client and I am trying to use factory girl to create the twitter objects for testing. When I create them individually it is fine. But, if I try to associate them I get the error below. Factory.define :status, :class => Twitter::Status,...

What methods should go in my DDD factory class?

I am struggling to understand what my factory class should do in my DDD project. Yes a factory should be used for creating objects, but what exactly should it be doing. Consider the following Factory Class: public class ProductFactory { private static IProductRepository _repository; public static Product Creat...

Is it OK to pass parameters to a Factory method?

One of the ways to implement Dependency Injection correctly is to separate object creation from business logic. Typically, this involves using a Factory for object creation. Up until this point, I've never seriously considered using a Factory so I apologize if this question seems a little simplistic: In all the examples of the Factory...

Isn't the Factory pattern the same thing as global state?

Let's say I have a class like this: class MonkeyFish { MonkeyFish( GlobalObjectA private: GlobalObjectA GlobalObjectB GlobalObjectC } Without a factory, I need to do the following in order to instantiated a MonkeyFish. GlobalObjectA a; GlobalObjectB b; GlobalObjectC c; int main() { MonkeyFish * monkey_f...

What are some patterns for creating views and controllers in an MVC or MVP app?

I'm working on a MVC/MVP GUI for editing a document. The document has a tree structure, with some nodes representing text, others images. The app model also includes a command stack, with commands operating directly on the model. Since different nodes have radically different controls, I'm planning on implementing individual MVC/MVP t...

What is the name of this factory type pattern and how do I represent it in UML?

Example: I have several types, e.g. Wheel, Brake, Engine, Clutch, AutoBox, ManualBox, ElectricWindow, RearParkingSensor, HeatedSeats. These will all inherit a ICarPart marker interface (could be an attribute (java annotation), but doesn't matter at this stage). I then write my Car class that can represent all car types, e.g. class Ca...

Passing data object to Factory in PHP

Please help me to implement Factory design pattern for the task. I working on scheduled message sending web application. User can specify his own scheduled sending plan, and messages will be delivered when it have to. User can choose only one of 3 reccuring types: monthly, weekly, daily. For this 3 reccuring types algorithm is similar: ...

Abstract storage of data for class based on environment(web/windows).....

I have a class and the storage of its information is going to depend on if it is getting consumed by a web or windows application. I was going to use the factory pattern to pass out the correct object. I guess the caller would then store that object appropriately if I did not want to have recreate the object. Anybody have other sugges...

Axis SecureSocketFactory - Setting the constructor attributes

I have a customer SecureSocketFactory set to be used by Axis when making an https connection using the following property: AxisProperties.setProperty("axis.socketSecureFactory", "com.metavante.csp.model.manager.mobilepayments.MonitiseSSLSocketFactory"); When this class is instantiated by Axis the constructor with a Hashtable (attributes...

How to handle a massive factory in a cleaner fashion

My development team has run into a design issue. I'm hoping someone can help me clean this part of the architecture up a bit. In my system, I have an enum with 250 members [one member represents a distinct drop down]. In order to populate the drop downs on any given window, that form sends in the enum members that relate to the drop do...

Is it possible to use a c# object initializer with a factory method?

I have a class with a static factory method on it. I want to call the factory to retrieve an instance of the class, and then do additional initialization, preferablly via c# object initializer syntax : MyClass instance = MyClass.FactoryCreate() { someProperty = someValue; } vs MyClass instance = MyClass.FactoryCreate(); instance....

Python dynamic function names

I'm looking for a better way to call functions based on a variable in Python vs using if/else statements like below. Each status code has a corresponding function if status == 'CONNECT': return connect(*args, **kwargs) elif status == 'RAWFEED': return rawfeed(*args, **kwargs) elif status == 'RAWCONFIG': return rawconfig(*arg...

Linking two Abstract Factory Patterns in Java.

I am writing a quote-matching program in which two Abstract Factory Patterns are required, these are two interfaces; QuoteFactory and ModeFactory. ModeFactory switches between EasyMode and HardMode and QuoteFactory picks out Quotes between several different subjects (i.e. PoliticalQuotes, SportsQuotes). In short, the user will pick a mod...

Factory class knows too much

UPDATED I've updated the example to better illustrate my problem. I realised it was missing one specific point - namely the fact that the CreateLabel() method always takes a label type so the factory can decide what type of label to create. Thing is, it might need to obtain more or less information depending on what type of label it wa...