language agnostic - How do you create your Factories? -


So, coming to the subject of factories, I am thinking how they have been established.

From where I stand, I can see 3 types of units:

all in one

A factory that originally All the sections used in an application are included. It seems that this is just a factory to be a factory, and does not really feel structured.

Example (Where classes, class B, and classes have nothing in common with :

  class factory {public static function buildClassA () Public static function buildClassB () public static function buildClassC ()}  

The given code samples are in PHP However, this question is language-agnostic.

Built-in Factory

Next is mixing in fixed works with regular functions like Wish (See)

Example:

  class ClassA {public static function buildClass () public function __construct ()}  

Factory on-the-side

The last one I can think is a factory for individual sections of individual sections, or sections. The variable used in the manner seems.

Example (where class, B, and C are related, and 1, 2, and 3 are related):

  Class fac ToryAlpha {public static function buildClassA () public static function buildClassB () public static function buildClassC ()} class factory Numeric {public static function buildClass1 () public static function buildClass2 () public static function buildClass3 ()}  

My question is: Are all these bad thoughts, any of them have bad thoughts? Are there other ways to build factories? Is any of these really good ideas? What is a good / best way to create a factory.

The issue of a factory seems to be that it is not necessary to know the code that uses it The concrete square will be constructed (this factory should be configured and handled). It seems that "all-in-one" and "factory-on-the-side" seem to get out.

I like the approach that uses the Java Library often: You have a stable method that makes a factory near the factory that has an example method that makes an example. It gives you two points of configuration (through system properties): The default factory IMPL has several types of settings, as it should be produced, and if these configuration options are not enough, then you can swap fully the factory IMPple You can.

For "all-in-one" versus "factory-on-the-side", I think a factory should not produce unrelated classes. Again, this Java word, every factory produces examples of a specific interface.

Dependency injection (where you have a container that all types of examples and injection in them).


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -