factory

How to package Factories in Java

Hi Guys, I was wondering how to package the factories I have in my application. Should the Factory be in the same pacakage as the classes that use it, in the same package as the objects it creates or in its own package? Thanks for yout time and feedback ...

Simple factory to retrieve files using constructor dependency injection

I want to create a class, that is flexible so I can switch implementations. Problem: Store files/documents Options: either store locally on the server filesystem, database or etc. Can someone help with a skeleton structure of the class, and how I would call it? I am not using an IoC, and don't really want to just yet. I just want the...

Removing the need for "new"

A nasty gotcha in javascript is forgetting to call new on a function meant to be instantiated, leading to this being bound to a different object (usually the global) instead of a fresh one. One workaround I read about is to check for it explicitly in the function-constructor using the following idiom: function SomeConstructor(x, y, ...)...

Abstract factory pattern on top of IoC?

I have decided to use IoC principles on a bigger project. However, i would like to get something straight that's been bothering me for a long time. The conclusion that i have come up with is that an IoC container is an architectural pattern, not a design pattern. In other words, no class should be aware of its presence and the container ...

How to properly implement a statemachine/Factory with structuremap?

Lets say i have a traditional statemachine/Factory implemented like public class StateMachine { public void ProcessState(StateEnum CurrentState) { switch (CurrentState) { case StateEnum.New: ProcessNewState(); break; case StateEnum.Waiting: P...

Assignment operator with Inheritance and virtual base class

Hello, I have an abstract virtual base class Foo from which I derive many other classes that differ in small ways. I have a factory that creates the derived classes and returns Foo*. One of my bigger problems is in my operator overloads, I need to make sure that the DFoo does not get operated on by DFoo1 (not shown). I have currently ha...

How to design an extensible type infrastructure with dependencies among each other

My application is an editor for connecting "modules" (through module ports). Ports have port types. Each port type has it's associated comparator. Two types are compatible if their attributes satisfy rules implemented in the comparator. I want users to extend the application by implementing new port types and rules how to connect them (...

Java - static factory method and switch statements

Hi guys, I am dealing with a set of message objects, each of which has a unique identifier corresponding to them. Each message can be constructed either from a Map, or from a ByteBuffer (the messages are binary, but we know how to transfer to and from a binary representation). The current implementation for constructing these messages...

DI container, factory, or new for ephemeral objects?

When dealing with objects that require data known only at runtime, such as a username and password, where should object instantiation happen: by using new, in a factory, or in a DI container? For example, I could just new an object once I have the data: UserCredentials creds = new UserCredentials(dialog.getUsername(), dialog.getPas...

Factory pattern with external dependency

I have a factory that makes objects that depend on an external object, do I pass it in the constructor of the factory? ...

How do you create your Factories?

So, coming upon the subject of Factories, I'm wondering how they are set up. From where I stand, I can see 3 types of Factories: All In One A factory that basically contains all of the classes used in an application. It feels like it is just having a factory for the sake of having a factory, and doesn't really feel structured. Exampl...

Return a reference to an instance of an object in PHP

I have a singleton factory and would like it to return a reference to the object instance so that I can use the singleton factory to destroy the instance and not have instances elsewhere in my code to survive. Example of what I would like to be able to do: $cat = CatFactory::getInstance(); $cat->talk(); //echos 'meow' CatFactory::destr...

Can I forbid calling static methods on object instance?

I have class with lots of conversion functions: class Something { public: string toXml(); string toJson(); ... static Something fromXml(string); // factory static Something fromJson(string); // factory ... }; Because static functions can be called on instance, it is easy to write code like this: Something...

Accessing factory_girl factories in *other* factories

I'm using the factory_girl plugin in my rails application. For each model, I have a corresponding ruby file containing the factory data e.g. Factory.define :valid_thing, :class => Thing do |t| t.name 'Some valid thing' # t.user ??? end I have lots of different types of users (already defined in the user factory). If I try the foll...

Factory Pattern for User Controls

I created a ASP.NET user control, and was wanting to create a factory with a method that allowed a control to be created via several parameters. Originally I was going to have a constructor on the user control with the parameters, but the parameters are really only provided to make creating the user control easier from some legacy cod...

What is the design pattern in this code?

Say I have a singleton-ish, factory-ish, reflection-ish class that receives some input, and spits back a new instance of a concrete implementation of some interface. What kind of design is this? Is there a better way to do what I want? Here's some code to illustrate the point: using System; using System.Collections.Generic; // stat...

feeding dependencies to a factory class via IoC?

I have a factory class that decides which of four available subclasses it should instantiate and return. As you would expect, all subclasses implement the same interface: public static class FooFactory{ public IFoo CreateFoo(FooEnum enum){ switch (enum) { case Foo1: return...

Using a Factory to replace instances by fakes from an Isolation Framework

A month ago I finished reading the book "Art of Unit Testing" and today I finally had time to start using Rhino Mocks with unit testing a service that sends/receives messages to devices (UDP) and saves/loads data from the database. Off course I want to isolate the database and the UDP communication. For example for database access, we ...

Is this a good candidate for a factory?

I want to create a voting system, where multiple domain objects can be voted on: a calendar event a comment a user So I figured I would create a Voteable interface for these items: interface Voteable { public function vote( User $user, $value ); } I thought this vote method would proxy a repository method, something like: cla...

asp.net mvc Overriding CreateController of DefaultContollerFactory ?

public override IController CreateController(System.Web.Routing.RequestContext requestContext, string controllerName) Is it normal that the controllerName passed into this function is sometimes "content"? how can i avoid that? public override IController CreateController(System.Web.Routing.RequestContext requestContext, string co...