factory-pattern

Beginner: Factory Pattern in Java

I am trying to write a Factory Pattern to create either a MainMode or a TestMode in my program. The code I was previously using to create these objects was: play = (isMode) ? new MainMode(numberRanges, numberOfGuesses) : new TestMode(numberRanges, numberOfGuesses, randNo()); My Game (play) would either create a Main...

Factory pattern in java

Hi, I was working with java code that is supposedly using the Factory pattern, but I'm not completely convinced by the pattern. My code does this: // the factory class SomeFactoryImpl { Set<SomeClass> getSomeListOfObjects(); } And somewhere in the code: { ... SomeFactory factory = new SomeFactoryImpl(); Set<SomeClass> li...

How would you code a repository pattern like a "factory" design pattern?

I thought I would rewrite this question (same iteration). The original was how to wrap a repository pattern around an EAV/CR database. I am trying a different approach. Question: How could you code a data repository in a "factory" design pattern way? I have a fixed number of entities, but the attributes to these entities are fairly c...

Do setup/teardown hurt test maintainability?

This seemed to spark a bit of conversation on another question and I thought it worthy to spin into its own question. The DRY principle seems to be our weapon-of-choice for fighting maintenance problems, but what about the maintenance of test code? Do the same rules of thumb apply? A few strong voices in the developer testing communit...

wcf and Factory\plugin pattern

I have an architectural question for you :) In my new project i'm developing a wcf service that has a "driverName" string input parameter and for that name the service must create a "driverType" class that implements an "IDriver interface" and execute a method. The application will be extensible and i want put other assembly with other d...

Cast from TObject to interface type

Hi, related to my last question, I now have the following problem: function TNodeFactory <T>.CreateNode (ID : Integer) : INodeInterface <T>; var NodeClass : TClass; begin NodeClass := FindRegisteredClass (ID); Result := NodeClass.Create; end; This yields a compiler error: E2010 Incompatible Types: 'INodeInterface<TNodeFa...

Does linq and nhibernate return the same type of collection?

Hi, If I design my db layer so I can swap it between a linq-to-sql or nhibernate implementation, I have to code against an interface. This means the return type between both linq and nhibernate have to be the same i.e. List etc. Is the list type the same? ...

How to use factory classes with linq for sql?

Hi, I have a model on top of my database model and map the objects in my Repository. However, apparently it makes a difference whether I "select new" directly in my GetUsers or "select factoryresult" as implemented below. I get the error at runtime, that the method CreateFromDbModel does not have a translation to sql (System.NotSupport...

Opposite factory pattern

I was wondering if there is an opposite pattern of the factory pattern. For example, when a certain object needs to be deleted some extra work needs to be done, to undo the configuration which was performed in the factory object. Extending the factory object with a Delete method for instance seems wrong, since the factory pattern is a s...

C# Factory Pattern

I am building a search application that has indexed several different data sources. When a query is performed against the search engine index, each search result specifies which data source it came from. I have built a factory pattern that I used to display a different template for each type of search result, but I've realized that thi...

Am I Using A Factory To Promote Polymorphism?

Hello! My first question is basically asking for a code-review. Does the code I'm about to provide use a Factory to promote Polymorphism? Its written in PHP. Here are the basic requirements: Pass a long url to a library and return a shortened url. Along with the long url, pass user properties to attempt to locate the users specifi...

What's the benefit of calling new on an object instance?

I'm reading Programming Perl, and I found this code snippet: sub new { my $invocant = shift; my $class = ref($invocant) || $invocant; my $self = { color => "bay", legs => 4, owner => undef, @_, # Override previous attributes }; return bless $self, $class; } With...

StructureMap Configuration Per Thread/Request for the Full Dependency Chain

I've been using Structuremap for a few months now, and it has worked great on some smaller (green field) projects. Most of the configurations I have had to set up involve a single implementation per interface. In the cases where I needed to choose a specific implementation at runtime, I created a factory class that used ObjectFact...

Abstract Factory Question

Hello, I am trying to understand the Abstract Factory design pattern. I am having a lot of trouble with it. I am trying to use the following example to develop a UML class diagram: Car designers can design many different types of cars. Cars can have two doors, or they can have four doors. Cars can be four-wheel drive, or they can be tw...

Why can't I get Type.GetType() to find the type of my plugin instance referenced in app.config?

So here's the deal. I've got my solution which has a few projects in it: A wrapper project - this is just a console app that's currently standing in for a windows service during debugging. A worker project - this contains the guts of the code. This way I can easily debug the code for the windows service without the headache. A plug...

Spring formBackingObject, Business Object Creation, and Factories

Design question for using Business Objects as formBackingObjects in a Spring SimpleFormController. Our controller's responsibility is to allow an End User to add a new Business Object to our web application. So we are passing our Business Object though the formBackingObject(HttpServletRequest request) method. However, we've run into a...

building a factory with object repository in C++?

I want to create a factory for creation of objects implementing an abstract interface, which would return a reference to the object that is kept internally, and objects are not replicated. The idea is pretty much the same as in the log4cxx/log4j Logger class design. I would also like to hide as much details from the client as possible, i...

Singleton in Conjunction with the Factory Pattern in PHP5

What is the best method for using singleton design pattern in conjunction with the factory method pattern in PHP5? My simplest usage scenario for this is instantiation selective database connection only once for each database type. ...

What's wrong with my factory?

I've got some code like this: public abstract class Foo { public static Foo getFoo() { return new FooImpl(); } abstract void DoFoo(); private class FooImpl extends Foo { public FooImpl() { } @Override void DoFoo() { } } } But Eclipse is telling me No enclosing instance of type Foo...

Constructor vs. Factory in .NET Framework

Below is an article about .net framework's use of patterns. I'm not sure I understand the bolded part in the excerpt below. Is it implying if you change the details of creating the object, you (might) change the constructor arguments? There are many cases in the Framework where you can obtain a new instance of a struct or class ...