factory-pattern

Unity: Register and resolve class with generic type

岁酱吖の 提交于 2019-11-30 20:30:39
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>(); ICollectionWrapper<T> CreateCollection<T>(IEnumerable<T> items); ICollectionWrapper<T>

how to create a factory in zend framework 2?

落花浮王杯 提交于 2019-11-30 19:48:32
in my Module.php i have the fallowing methods that i would like to move them in a factory class so that i wont clutter the Module class : public function getControllerConfig() { return array( 'factories' => array( 'account-index' => function ($controllerManager) { $serviceManager = $controllerManager->getServiceLocator(); $accountService = $serviceManager->get('account-service'); return new Controller\IndexController($accountService); } ) ); } public function getServiceConfig() { return array( 'factories' => array( 'account-service' => function ($serviceManages) { return new Service\Account; }

using the command and factory design patterns for executing queued jobs

馋奶兔 提交于 2019-11-30 14:51:01
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": command = new CommandB(); break; case "C": command = new CommandC(); break; } command.Execute(); Is

instance factory methods Vs Static factory methods

喜欢而已 提交于 2019-11-30 10:28:33
问题 Can't all factory methods be static ? Does something that produces a product need state ? When is it appropriate to go for a instance factory or static factory method ? Can you provide me examples differentiating the two ? 回答1: Assuming that by "instance factory method" you're actually saying about the GoF "factory method", the term "static factory method" is described by Joshua Bloch in his book "Effective Java". Googling around I reached at these sites: Factory Method: http://sourcemaking

Factory Pattern in C++ — doing this correctly?

本小妞迷上赌 提交于 2019-11-30 08:47:38
I am relatively new to "design patterns" as they are referred to in a formal sense. I've not been a professional for very long, so I'm pretty new to this. We've got a pure virtual interface base class. This interface class is obviously to provide the definition of what functionality its derived children are supposed to do. The current use and situation in the software dictates what type of derived child we want to use, so I recommended creating a wrapper that will communicate which type of derived child we want and return a Base pointer that points to a new derived object. This wrapper, to my

public static factory method

血红的双手。 提交于 2019-11-30 04:57:02
First of all please forgive me if its a really dumb question, I am just trying to learn this language to its core. I am reading Effective Java and the very first chapter talks about Static factory methods vs. Constructors. Their pros and cons. Few things that are confusing to me are: class of an object returned by static factory method is nonpublic - what exactly does it mean? unlike constructors static factory methods are not required to create a new object each time they are invoked - How does this happen? I am invoking factory method only to obtain a new object and do we put a check in

DDD repository and factory

人走茶凉 提交于 2019-11-30 02:14:24
In my application a few layers. In this topic will focus on Domain and Infrastructure layers. I have repository interface ClientRepositoryInterface in Domain layer. And I have implementation of this interface ClientRepositoryImpl in Infrastructure layer. But to reconstitute the object in the middle of the cycle of its existence I need factory(ReconstitutionClientFactory). Call the factory will be in the repository. The book by Eric Evans is described as a normal practice. But where this factory(ReconstitutionClientFactory) should be located? In Domain or in Infrastructure layer? I think in

Replace factory with AutoFac

最后都变了- 提交于 2019-11-29 23:10:37
I'm accustomed to creating my own factories as shown (this is simplified for illustration): public class ElementFactory { public IElement Create(IHtml dom) { switch (dom.ElementType) { case "table": return new TableElement(dom); case "div": return new DivElement(dom); case "span": return new SpanElement(dom); } return new PassthroughElement(dom); } } I'm finally getting around to using an IoC container (AutoFac) in my current project, and I'm wondering is there some magic way of achieving the same thing elegantly with AutoFac? Short answer: Yes. Longer answer: First, in simple cases where a

Factory / Abstract Factory confusion

橙三吉。 提交于 2019-11-29 21:54:17
After ~10 months of procedural PHP, I'm now trying to wrap my head around basic OOP principles and design patterns. This is a hobby, and I haven't nearly as much time as I'd like to pursue it, so please forgive the rather low level of this question. My site (currently 100% procedural) is at heart a library. Visitors send the Library script 2 datapoints - an item type and item code . Library.php uses the item type to select an include, and the include grabs the code to hit the database and then build the page. Some examples: [type] [code] game RoTo map 32 unit 216 An example link would be

Real world examples of Factory Method pattern

♀尐吖头ヾ 提交于 2019-11-29 21:26:38
I just read Factory Method. I understand that it provides a way to delegate the instantiation to sub-classes. But I couldn't understand the possible uses in a real-world scenario. Can anyone give one typical example showing how Factory method pattern can be used so that I can relate to what I have read. A problem statement for which factory method pattern is the best solution would be sufficient to make it clear. A class implementing factory design pattern works as bridge between multiple classes. Consider an example of using multiple database servers like SQL Server and Oracle. If you are