factory-pattern

Doubt about instance creation by using Spring framework ???

Here goes a command object which needs to be populated from a Spring form public class Person { private String name; private Integer age; /** * on-demand initialized */ private Address address; // getter's and setter's } And Address public class Address { private String street; // get...

Example of how to make a data factory for core data access in cocoa (iPhone)?

I have been slowly learning iPhone development and seem to keep hitting walls where I can't figure out how to do what I want to do the right way :( Basically, I want a class that handles all interactions with the data layer, for example, getting a mutable array of some list of objects from the data store. This is pretty trivial in othe...

factory class in PHP, no __construct? What method names do I use?

I have a factory class I'm making in PHP. Each instance represents a row from a database table. Since I'll be dealing with dozens of database rows, it would be silly to have each instance do a select on instantiation. So I have a method to just dump values in to the object, for use in conjunction with a database query that returns a lo...

C# Generics and abstract factory pattern - or some way of doing something similar

I am trying to write a sort of extendable data layer for my application One of the "repositories" is an in-memory implementation of my abstract store class public abstract class Store<TEntity, TIdentifier> : IStore<TEntity, TIdentifier> where TEntity : StorableEntity<TIdentifier> { //abstract methods here public abs...

How to make a constructor return a subclassed object.

I just read a book on object-oriented programming patterns. It describes a Factory pattern by which you can make a call to a static factory method of an object and the object will return a new object of expected type, but it will be subclassed appropriately. My question, can this functionality be provided by a constructor for the cla...

Factory Method pattern to avoid instantiation of objects based on conditional logics

In a scenario like below where an object needs to be intantiated based on some conditional logic, can the factory method pattern help to avoid client code getting cluttered due to number of if/elseif conditions (which would also be a maintenance nightmare if more and more products needs to get created due to different variations of logic...

Why should one use factory method to create objects

Possible Duplicates: Factory Pattern. When to use factory methods? Why do static Create methods exist? Though I know what is Factory Design Pattern. But I am unable to comprehend what are the benefits of using it. Why should we create objects using Factory Design Pattern. ...

Factory Pattern but with object Parameters

Take the following classic factory pattern: public interface IPizza { decimal Price { get; } } public class HamAndMushroomPizza : IPizza { decimal IPizza.Price { get { return 8.5m; } } } public abstract class PizzaFactory { public abstract IPizza CreatePizza(ItalianPizzaFactory...

Convert a class to a subclass on instantiation

I'm writing a framework for querying the Mediawiki API. I have a Page class which represents articles on the wiki, and I've also got a Category class, which is-a Page with more specific methods (like being able to count the number of members in the category. I've also got a method Page#category? which determines if an instantiated Page o...

What is the pattern used in log4j

Hi, I needed to understand the design pattern(s) used in log4j library. Since it provides loggers for various classes, it it a factory ? Any more inputs/pointers on these is greatly appreciated.. ...

Design pattern name: Is it a factory?

The following class shows something similar to a real use case. It returns always the same instance for the same thread. public class LookingForName { private static final ThreadLocal<Something> threadLocal = new ThreadLocal<Something>(){ @Override protected Something initialValue() { ...

Abstract Factories not possible in php < 5.3?

I was working on an abstract class to save on some code for a couple of classes. These classes are all factories that instantiate themselves through different static calls. I could save some code by putting all those methods in an abstract class. However, I ran into a late static binding problem... since our web host isn't using 5.3 or...

Factory pattern in Python

Hi, I'm currently implementing the Factory design pattern in Python and I have a few questions. Is there any way to prevent the direct instantiation of the actual concrete classes? For example, if I have a VehicleFactory that spawns Vehicles, I want users to just use that factory, and prevent anyone from accidentally instantiating Car...

inherited factory method should return instances of own class not inherited class

I have a class that has a complex static factory method, lets call it ClassA. I have extended ClassA into ClassB and I want ClassB's factory method to do everything that ClassA's factory method does, except return a ClassB. class ClassA{ static public function Factory($construct_args, $contents){ $new = new ClassA($construct_a...

Type Casting and the Factory pattern

Hello experts, I'm having a hard time figuring out how to implement a factory pattern in a DTO mapper I'm trying to create. I'm pretty sure I need to rethink my design. Here is a very small example of what I'm running in to: public abstract class Person { public string Name { get; set; } public decimal Salary { get; set; } }...

Object factory implementation

I`m want to create an object factory in C#. I want my objects to be created only via this object factory, how to achieve this? I know how to make a simple object factory, like satic class with public methods that are creating and initializing my objects. But I need to make sure people can only create object instances via object factory, ...

Some doubts about what Factory does

Hi, I'm not really sure to understand completely the factory pattern. Let's say I have a class Customer which has basically the following methods: CreateCustomer - static, creates a customer from scratch and adds it to the database, LoadCustomer - static, loads an instance of a Customer from the database, KillCustomer - not static, r...

Create generic class with internal constructor

Is it possible to construct an object with its internal constructor within a generic method? public abstract class FooBase { } public class Foo : FooBase { internal Foo() { } } public static class FooFactory { public static TFooResult CreateFoo<TFooResult>() where TFooResult : FooBase, new() { return new TFooResult(...

Factory pattern for test and live web services

Can web services be used in a factory pattern given that the code is auto-generated and I do not want to alter it (to add a base class for example)? A reason to do this would be if you had 2 web services that were identical but one was for test data and one was for live data and you wanted to switch between the services based on the env...

Question about Factory Design Architecture

Consider this example The Interface interface IBusinessRules { string Perform(); } The Inheritors class Client1BusinessRules: IBusinessRules { public string Perform() { return "Business rule for Client 1 Performed"; } } class Client2BusinessRules: IBusinessRules { public string Perform() { re...