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 ...
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?
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)?
If yes then how?
If not.. then what is your approach?
...
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...
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);
...
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,...
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...
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...
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...
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...
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...
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:
...
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...
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...
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...
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....
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...
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...
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...