factory-pattern

Parameterized Factories Using Ninject

风流意气都作罢 提交于 2019-12-04 15:59:23
问题 How to make Ninject to instantiate object based on variable on run time?. I am trying to inject the correct Repository in The Controller action - MVC 3 - based on parameter come from user input. If user input "BMW" it would bind ICarRepository to BMWRepository , and if he input "KIA" KiaRepository will be injected. [HttpPost] public ActionResult SearchResult(FormCollection values) { string carModel = values["model"]; ICarRepository myRepository = RepositoryFactory.getRepository(carModel); ...

Strategy Design Pattern, Generics and TypeSafety

血红的双手。 提交于 2019-12-04 12:09:33
问题 I want to create the following Strategy Pattern combined with Factory, but I want it to be typesafe. I have done the following till now: public interface Parser<T> { public Collection<T> parse(ResultSet resultSet); } public class AParser implements Parser<String> { @Override public Collection<String> parse(ResultSet resultSet) { //perform parsing, get collection Collection<String> cl = performParsing(resultSet); //local private method return cl; } } public class ParserFactory { public enum

Factory Pattern in JavaScript

淺唱寂寞╮ 提交于 2019-12-04 09:47:57
I want to decouple the creation of JavaScript objects from the code that is using it so that I have the flexibility of replacing one object implementation with other object implementation having same signature without touching much of the code. In order to achieve this I come up with the concept of Repository and a Factory Method to create objects. Here is the implementation: //The Factory Method function ObjectFactory() {} ObjectFactory.create = function (o) { var args = [].slice.call(arguments, 1); function F() {} F.prototype = o.prototype; var instance = new F(); o.apply(instance, args);

Laravel 4: Confused about how to use App::make()

时光总嘲笑我的痴心妄想 提交于 2019-12-04 09:44:25
问题 I am trying to follow the repository pattern outlined in this article http://code.tutsplus.com/tutorials/the-repository-design-pattern--net-35804#highlighter_174798 And I am trying to instantiate a class in Laravel using App::make() (Which I am guessing is Laravel's factory pattern?) and I am trying to parse arguments to my class but I can't work out how to do it. Code: namespace My; class NewClass { function __construct($id, $title) { $this->id = $id; $this->title = $title; } } $classArgs =

Data Layer Abstract Factory

半腔热情 提交于 2019-12-04 08:37:30
I'm new on developing an Abstract Factory pattern, and would like to create an abstract factory in the data layer that will help me link this layer to any other databases for example sql and oracle. Can you help me on developing this task please. Note that the connection string of the database will be found in this layer not in the presentation.. Thanks EDITED public abstract class Database { public string connectionString; #region Abstract Functions public abstract IDbConnection CreateConnection(); public abstract IDbCommand CreateCommand(); public abstract IDbConnection CreateOpenConnection(

Simple Factory vs Factory Method: Switch statement in factory vs. client

好久不见. 提交于 2019-12-04 08:16:35
I understand that one of the main advantages of the Factory Method over Simple Factory is that it doesn't violate the Open-Closed SOLID Principle. That is, the former doesn't require modifying the switch statement when new types are added. There is one piece on which I am hoping to get clarification. If I were to use a simple factory, I would have a factory like this (simplified): public class ObjectFactory { public static IObject CreateObject(ObjectTypeEnum objectType) { switch (objectType) { case TypeA: return ObjectA; break; case TypeB: return ObjectB; break; case TypeC: return ObjectC;

Factory Design Pattern (needing critique)

北城以北 提交于 2019-12-04 08:01:05
问题 I am putting together an explanation and code example of this design pattern, attempting to help others around me grasp it (along with helping myself to master the pattern as well). What I am looking for is opinions & or critique of my explanation and code sample...thanks! What is the factory pattern? The factory pattern utilizes a particular dedicated "object creator object" to handle creation of - and most times instantiation of - objects, similar to a real world factory. Real world example

Implement a simple factory pattern with Spring 3 annotations

▼魔方 西西 提交于 2019-12-04 07:26:43
问题 I was wondering how I could implement the simple factory pattern with Spring 3 annotations. I saw in the documentation that you can create beans that call the factory class and run a factory method. I was wondering if this was possible using annotations only. I have a controller that currently calls MyService myService = myServiceFactory.getMyService(test); result = myService.checkStatus(); MyService is an interface with one method called checkStatus(). My factory class looks like this:

Unity: Register and resolve class with generic type

社会主义新天地 提交于 2019-12-03 20:54:11
问题 I'm using Unity and try to follow to SOLID-principles as far as possible. Therefore all implementations only have dependencies to interfaces. I have a collectionwrapper which looks like this: public interface ICollectionWrapper<TModel> { int TotalCount { get; set; } IEnumerable<TModel> Items { get; set; } } Now I want to create the instance of ICollectionFactory<T> with a factory. This is what I got so far: public interface ICollectionWrapperFactory { ICollectionWrapper<T> CreateCollection<T>

using the command and factory design patterns for executing queued jobs

泄露秘密 提交于 2019-12-03 20:15:45
问题 I have a list of jobs queued in the database which I need to read from database and execute them in parallel using threading and I have a list of command classes to execute each of those jobs all implementing a common interface (command pattern). but when I retrieve the pending jobs from the database, I will need to instantiate the right command object for each job something like this (in a factory class) ICommand command; switch (jobCode) { case "A": command = new CommandA(); break; case "B"