factory-pattern

Is this the correct way to use and test a class that makes use of the factory pattern?

I don't have a lot of experience with the factory pattern and I've come across a scenario where I believe it is necessary but I'm not sure the I've implemented the pattern correctly and I'm concerned about the impact it's had on the readability of my unit tests. I've created a code snippet that approximates (from memory) the essence of ...

does a factory just return an implementation of an interface?

does a factory just return an implementation of an interface? Is that the job? ...

C#: Abstract Strategy base class serving as Abstract Factory for Strategy objects

I am trying to create a web-based tool for my company that, in essence, uses geographic input to produce tabular results. Currently, three different business areas use my tool and receive three different kinds of output. Luckily, all of the outputs are based on the same idea of Master Table - Child Table, and they even share a common Mas...

Storing Factory Pattern Products

Right now, I've got a switch statement which is being used to create objects based on a string. There are three types of objects which extend an abstract generic object. I should really be using a factory pattern, which I'm figuring out right now. My issue is thus: I appreciate the flexibility of the factory pattern, but right now I'm st...

Need Help With Provider Design Patterns

Hi. I need some help with DLL architecture / design patterns / OO. I have been learning about class factory design patterns as a solution to my current challenge and could use some feedback at this point. I have three classes that are custom wrappers for ASP.NET 2.0's ProfileProvider, MembershipProvider, and RoleProvider. I'd li...

Using Ninject IOC to replace a factory

I've got a factory method inside a parser. Essentially as I load a token I look up the handler for that token, or drop through to the default handler. I've implemented this as a switch and as a Dictionary<string,Type> but both approaches require me to store the mapping somewhere else than the handler class. We are using Ninject for IOC ...

Why do some classes restrict direct instantiation?

I have encountered various classes that don't allow creation of their instance directly. Rather we have to create their instance from some other class's static method or it own static method. For example: B b = A.getB(); or B b = B.getInstance(); What reason is behind that? Why don't they allow creating instance directly, as in: ...

Is this how the Factory Pattern works?

The Singleton and the Registry patterns were very simple and easy for me to understand right away but the Factory pattern has been something I haven't been able to get my brain to interpret 100% yet. I think I might understand it now, I have wrote a sample code below, please review and tell me if this is the proper use of the Factory pa...

WCF Dependency injection and abstract factory

I have this wcf method Profile GetProfileInfo(string profileType, string profileName) and a business rule: if profileType is "A" read from database. if profileType is "B" read from xml file. The question is: how to implement it using a dependency injection container? Mark Seemann author of book "Dependency injection in .net" Sugge...

DDD Book, Eric Evans: Please explain what is meant by "The FACTORY should be abstracted to the type desired rather than the concrete class(es) created."

In the book Domain Driven Design, by Eric Evans, in Chapter 6 in the section on "Factories" (page 139) it says the following: "The two basic requirements for any good FACTORY are: ... "2. The FACTORY should be abstracted to the type desired rather than the concrete class(es) created." Could you please elaborate on what is meant by t...

Factory Pattern - Question with Auto-wire up

I'm using subsonic2's generated classes and wanting to add a layer of abstraction for testing, I created a basic interface, as such... public interface IController<TCollection> where TCollection : class { TCollection FetchAll(); TCollection FetchByID(object id); TCollection FetchByQuery(Query query); bool Delete(obj...

how to create a factory that dynamicly extend a class so its type changes but it inherents parent methods.

What I would like to do is have a static factory function that you give it a series of attributes and it returns an object that is of a previously undeclared class that extends a known class. Basically: <?php class foo{ public $a; function increment($b = 1){ $this->a += $b; } } function factory($name, $a){ //returns an ob...

Alternative to Factory Pattern when creating templated objects - C++

Hi, I want to implement a Mesh class for a CG project, but have run into some problems. What I want to do is a Mesh class that hides implementation details (like loading to a specific API: OpenGL, DirectX, CUDA, ...) from the user. Additionally, since the Mesh class will be used in research projects, this Mesh class has to be very flexi...

Model inheritance, the Factory pattern, and self-parsing in Ruby-on-Rails

Hi all- I am working with a site that will be pulling down feeds from a lot of different sources, and then saving those streams into a common model, in this case a trait. An example of the code from within the FeedEntry class might be: feed = Feedzirra::Feed.fetch_and_parse(feed_url) add_entries(feed.entries) ... def self.add_entrie...

Flyweight and Factory problem with IDisposable

I seem to be mentally stuck in a Flyweight pattern dilemma. First, let's say I have a disposable type DisposableFiddle and a factory FiddleFactory: public interface DisposableFiddle : IDisposable { // Implements IDisposable } public class FiddleFactory { public DisposableFiddle CreateFiddle(SomethingThatDifferentiatesFiddles s...

Is this a perfect problem for the factory pattern?

I want to design the file storage part of my application with some flexibility, so one can store files in either S3 or on the web server's hard drive. I also want this to be flexible on a per user basis, so in their user settings they can choose if they want their files stored in S3 or on the servers file system. I am thinking of somet...

Is there a better way to use Castle Windsor's API for Factories?

I am open to other IoC containers, such as NInject and StructureMap if they are much cleaner than this. I hear that StructureMap just introduced "containers" that may simplify this , perhaps? As the title says, is there a better way? This seems like a lot of code, just to register an object that requires a factory to create it. // Th...

Real world examples of Factory Method pattern

I just read Factory Method. I understand that it provides a way to delegate the instantiation to sub-classes. But I couldn't understand the possible uses in a real-world scenario. Can anyone give one typical example showing how Factory method pattern can be used so that I can relate to what I have read. A problem statement for which fa...

Ideatryout: Typed Providerfactory

I've been thinking about starting a new project in C#.NET (4.0RC) for a couple of days now. The end result of the project would be a class-library consisting of what I for now call a "ProviderFactory", a couple of interfaces (or abstract classes) and a default "ProviderType" or two. First of all I might need/decide to change the naming ...

Question regarding factory pattern

I have a factory class to build objects of base class B. The object (D) that uses this factory receives a list of strings representing the actual types. What is the correct implementation: the factory receives an Enum (and uses switch inside the Create function) and D is responsible to convert the string to Enum. the factory receives a...