factory

C# generic factory method

Perhaps this is a simple newbie C# question, but so be it---it will be a fresh break from my other questions, which are so difficult that no one knows the answer to them. :) Let's say I have a generic type in C#: Thing<T> And let's say I want to make a thing using a static factory method. In Java, this is no problem: public static <...

Implementing a generic service factory or provider in Autofac

I have an interface, for example ISomeService. ISomeService provides a common service, but the implementations may vary. As such, they will have different dependencies. Consider: interface ISomeService { void DoSomething(); } class SomeServiceA : ISomeService { public SomeServiceA(DependencyOne one, DependencyTwo two) ...

Parameterized Factory & product classes that cannot be instantiated without the Factory

I'm working on implementing a Factory class along the lines of what is proposed in this response to a previous question: http://stackoverflow.com/questions/410823/factory-method-implementation-c/534396#534396 It's a Factory that stores a map from strings to object creation functions so I can request different types of objects from the ...

Dynamic base class and factories

I have following code: class EntityBase (object) : __entity__ = None def __init__ (self) : pass def entity (name) : class Entity (EntityBase) : __entity__ = name def __init__ (self) : pass return Entity class Smth (entity ("SMTH")) : def __init__ (self, a, b) : self.a...

Using multiple wcf services, factory class to return proxyclient

I have multiple services in my application. WebService1, WebService2,WebService3 and so on.. All the services have same methods, but they are hosted on different IPs. Now when a client calls a methodA(1) then WebService1Client.Method() should be called; client calls a methodA(2) then WebService2Client.Method() should be called. I do...

c++ factory and casting issue

I have a project where I have a lot of related Info classes and I was considering putting up a hierarchy by having a AbstractInfo class and then a bunch of derived classes, overriding the implementations of AbstractInfo as necessary. However it turns out that in C++ using the AbstractInfo class to then create one of the derived objects ...

How do I handle an exception in an ASP.NET MVC controller factory

I have an ASP.NET MVC 2 application with a custom StructureMap controller factory to handle dependency injection for my controllers: public class StructureMapControllerFactory : DefaultControllerFactory { public override IController CreateController(RequestContext context, string controllerName) { Type controllerType = b...

PDO FETCH_INTO Factory?

I have a factory called ProductFactory I can create a product like so: $product = ProductFactory::getProduct($id); Now depending on what type of product we are getting, this function may return a class of type Product or a descendant or Product. But using the method above, the $product class would be responsible for connecting to th...

Twisted factory protocol instance based callback

Hey, I got a ReconnectingClientFactory and I wonder if I can somehow define protocol-instance-based connectionMade/connectionLost callbacks so that i can use the factory to connect to different hosts ans distinguish between each connection. Thanks in advance. ...

Object generator pattern

I have a class that represents a pretty complex object. The objects can be created by many ways: incremental building, by parsing text strings in different formats and by analyzing binary files. So far my strategy was as follows: Have the constructor (__init__, in my case) initialize all the internal variables to None Supply different ...

Database factory class design

Hi i have this class to instantiate DAL classes: public class Factory { public static T GetInstance<T>() where T : new() { return new T(); } } I want to make my application capable of using multiple databases. I was planning on setting the database in my web.config and then pass in that setting possibly to the fac...

Is the typical C++ implementation of Factory class flawed?

I have the need to implement factory class in C++, but when I was thinking about that, I found one big problem that I couldn't solve, and I found out, that all factory implementation examples around are flawed in the same way. I'm probably the one who is wrong, but please tell me why. So here is simple "typical" factory implementation, ...

PHP class problem

class Gdn { const AliasDispatcher = 'Dispatcher'; protected static $_Factory = NULL; public static function Dispatcher() { $Result = self::Factory(self::AliasDispatcher); return $Result; } public static function Factory($Alias = FALSE) { if ($Alias === FALSE) return self::$_Factory; ...

Consequences of changing __type__

I'm attempting to create what a believe (in my ignorance) is known as a class factory. Essentially, I've got a parent class that I'd like to take an __init__ argument and become one of several child classes. I found an example of this recommended on StackOverflow here, and it looks like this: class Vehicle(object): def __init__(self, ...

Can I define a class with no public constructor and place a factory method for this class objects in a different class in Scala?

For example (maybe a bit clumsy from a real life view, but just to illustrate): "User" is a case class containing user name and id. Id can be never set manually, and a User class instance with no id set has no sense. A UserBase class maintains users base and has a "getUser (name : String) : User" method returning a consistent User inst...

Cleanly duplicate an instance of a baseclass or subclass in C++?

In the trivial example inheritance hierarchy: class Food { virtual ~Food(); }; class Fruit : public Food { virtual ~Fruit(); }; class Apple: public Fruit { virtual ~Apple(); } class Vegetable: public Food { virtual ~Vegetable(); } I wish to create a method that can clone an object from its subclass or baseclass inst...

Order of message passing for object destruction / teardown

This is a language agnostic question about object oriented design, particularly the passing of messages regarding object destruction. This whole question could just as easily use the terms Parent and Child instead of Factory and Item. Which object should be responsible for an objects tear-down process; the object itself, or the factory...