factory-pattern

Factory Pattern: typedef Class *(createClassFunction)(void)

若如初见. 提交于 2019-12-02 08:53:56
What does typedef Class *(createClassFunction)(void) (or another variation is typedef Class* (__stdcall *CreateClassFunction)(void) )stand for? What does it mean? How am I supposed to explain it? Especially in the context of Factory Patterns... Reading C type expressions createClassFunction is a typedef for a function taking no arguments and returning a Class * . With that declaration, a pointer to such a funciton can obviously act as factory for a Class . Usage might be as follows: // the class factory Class * MostTrivialFactoryKnownToMan() { return new Class; } // another class factory Class

C# - Ninject, IoC and factory pattern

有些话、适合烂在心里 提交于 2019-12-02 07:27:37
问题 I have a console application where I need to execute a certain feature based on input from the user. If the user puts in "feature 1" -> I execute Feature 1, and so on. I am trying to write this project as clean and as generic as possible, and I want to use the IoC and SOLID concepts, and i am kinda stuck. What I have so far: public interface IFeature { String execFeature(); } and interface IFeatureFactory { IFeature createFeature(String input); } My first thought was just to have a switch

Constructor vs. Factory in .NET Framework

邮差的信 提交于 2019-12-02 05:36:31
问题 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 without calling its constructor yourself. The System.Convert class contains a host of static methods that work like this. To convert an integer to a Boolean, for

Factory pattern with Managed Ext Framework (MEF)

大兔子大兔子 提交于 2019-12-02 01:49:19
问题 I am trying to implement Factory Pattern with MEF. Here is my solution Core Project IClass ObjectFactory static Class(This is where the problem is) Project A [Export(typeof(IClass))] [ExportMetadata("Type", "TypeA")] public classA : IClass {} ProjectB [Export(typeof(IClass))] [ExportMetadata("Type", "TypeB")] public classB : IClass {} I am facing problem when I am trying to create object dynamically And here is factory class: public static class ObjectFactory { private static readonly

The best way to implement Factory without if, switch

[亡魂溺海] 提交于 2019-12-02 00:13:49
I was looking through many approaches to implement a Factory pattern in Java and still couldn't find a perfect one which doesn't suffer from both if/switch plus doesn't use reflection. One of the best that I found was inside Tom Hawtin's answer here: https://stackoverflow.com/a/3434505/1390874 But my biggest concern is that it stores a HashMap of Anonymous classes in a memory. The question is what do people think about using Class.newInstance() in addition to Tom Hawtin's answer? This will avoid us from storing unnecessary anonymous classes in memory? Plus code will be more clean. It will look

Constructor vs. Factory in .NET Framework

此生再无相见时 提交于 2019-12-01 23:21:57
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 without calling its constructor yourself. The System.Convert class contains a host of static methods that work like this. To convert an integer to a Boolean, for example, you can call Convert.ToBoolean and pass in the integer. The return value of this method call is a

Naming convention for GoF Factory?

 ̄綄美尐妖づ 提交于 2019-12-01 11:49:37
This pattern uses an abstract factory, and then an implementation of the factory. I am sure there is a standard naming convention for these two classes, but I don't know what it is. For example: public abstract class ChocolateFactory { }; public class MyChocolateFactory { } : ChocolateFactory What's the standard convention here? I'm thinking either ChocolateFactoryBase, or ConcreteChocolateFactory, but perhaps there is something else (much like Enums tend to be suffixed with Enum, e.g. PetTypeEnum so that you can do PetTypeEnum PetType; Hopefully this isn't subjective. The question and the

Naming convention for GoF Factory?

泪湿孤枕 提交于 2019-12-01 09:26:02
问题 This pattern uses an abstract factory, and then an implementation of the factory. I am sure there is a standard naming convention for these two classes, but I don't know what it is. For example: public abstract class ChocolateFactory { }; public class MyChocolateFactory { } : ChocolateFactory What's the standard convention here? I'm thinking either ChocolateFactoryBase, or ConcreteChocolateFactory, but perhaps there is something else (much like Enums tend to be suffixed with Enum, e.g.

Can I use Attributes so my Factory knows what it can/should instantiate without breaking the “Loosely-Coupled” rule?

杀马特。学长 韩版系。学妹 提交于 2019-12-01 06:33:33
问题 I have implemented a factory in my project and it was recently suggested that I use attributes on my classes so the factory can determine which class to instantiate and pass back. I am new to the world of development and trying to rigidly follow the loosely-coupled rule, I wondering if relying on "hooks" (being the attributes) goes against this? 回答1: I don't think that using attributes would be increasing the coupling between the factory and the class it creates, in fact, it would decrease

Passing Services using Dependency Injection and Factory Pattern in ASP.NET

浪尽此生 提交于 2019-11-30 22:39:05
I am using ASP.NET Core, I know that such Logging mechanism is already provided by the framework, but using this to illustrate my problem. I am using kind of Factory pattern to build the Logger class, since I don't know the type of logging (because it is stored in DB). The ILogger Contract Log(string msg) Then LoggerFactory will return an ILogger after creating a Logger based on param passed from DB: public class LoggerFactory { public static Contracts.ILogger BuildLogger(LogType type) { return GetLogger(type); } //other code is omitted, GetLogger will return an implementation of the related