factory-method

What Are Some Examples of Design Pattern Implementations Using JavaScript?

I'm a moderately skilled programmer using JavaScript but I am no guru. I know you can do some pretty powerful things with it, I just haven't seen much other than fairly basic DOM manipulation. I'm wondering if people could provide some examples of traditional design pattern concepts such as Factory Method, Singleton, etc using JavaScript...

UML: Can someone explain the Factory Method diagram for me?

i dont have an idea what the broken arrow from the ConcreteCreator to the ConcreteProduct means. i searched in the internet and i came up with "Dependency". can someone explain the dependency in layman's terms? thanks! image grabbed from http://www.dofactory.com/Patterns/PatternFactory.aspx ...

Can I implement the Factory Method pattern in C++ without using new?

I'm working in an embedded environment (Arduino/AVR ATMega328) and want to implement the Factory Method pattern in C++. However, the compiler I'm using (avr-gcc) doesn't support the new keyword. Is there a way of implementing this pattern without using new? ...

Should a factory method of a custom container return the newly created instance?

I have a custom collection Doohickeys indexed by keys. This collection has a factory method createDoohickey(key) and an accessor Doohickey(key). Should createDoohickey(key) return the new object or should it return void? In the first case, I would use it like this myDoohickey = doohickeys.createDoohickey(key); doStuff(myDoohickey); i...

Is a switch statement applicable in a factory method? c#

I want to return an Interface and inside a switch statement I would like to set it. Is this a bad design? private IResultEntity GetEntity(char? someType) { IResultEntity entity = null; switch (someType) { case 'L': //life entity = new LifeEntity(); break; ...

How to use factory classes with linq for sql?

Hi, I have a model on top of my database model and map the objects in my Repository. However, apparently it makes a difference whether I "select new" directly in my GetUsers or "select factoryresult" as implemented below. I get the error at runtime, that the method CreateFromDbModel does not have a translation to sql (System.NotSupport...

Factory method signature for aggregate root

I want to write a factory method to instantiate an entity that is an aggregate root. Should the method accept the aggregated child entities and values as instantiated objects, or should it accept only primitive types? For example, if I had an entity Computer composed of a Processor and a Memory object, should the factory method take th...

Is this a good factory method implementation?

I'm working on a module that requires a strictly decoupled interface. Specifically, after instantiating the root object (a datasource), the user's only supposed to interact with the object model via interfaces. I have actual factory objects (I'm calling them providers) to supply instances that implement these interfaces, but that left ...

Am I overdoing it with my Factory Method?

Hello. Part of our core product is a website CMS which makes use of various page widgets. These widgets are responsible for displaying content, listing products, handling event registration, etc. Each widget is represented by class which derives from the base widget class. When rendering a page the server grabs the page's widget from th...

Does the Factory Method pattern violate the Open/Closed principle?

Does the Factory Method pattern (not to be confused with the Factory or Abstract Factory patterns) violate the Open/Closed principle? Update: To clarify, I'm referring to the scenario where a concrete class has static factory methods on it. For example (this is from the Wikipedia page on FMP): class Complex { public static Complex...

Abstract Methods in "Product" - Factory Method C#

I have a simple class library (COM+ service) written in C# to consume 5 web services: Add, Minus, Divide, Multiply and Compare. I've created the abstract product and abstract factory classes. The abstract product named WS's code: public abstract class WS { public abstract double Calculate(double a, double b); public abstrac...

How can I create a generic constructor? (ie. BaseClass.FromXml(<param>)

I'm not sure how to describe this but I'm trying to create a base class that contains a shared (factory) function called FromXml. I want this function to instantiate an object of the proper type and then fill it via an XmlDocument. For example, let's say I have something like this: Public Class XmlObject Public Shared Function Fro...

What should I do if i have a factory method which requires different parameters for different implementations?

I have an interface, IMessage and a class which have several methods for creating different types of message like so: class MessageService { IMessage TypeAMessage(param 1, param 2) IMessage TypeBMessage(param 1, param 2, param 3, param 4) IMessage TypeCMessage(param 1, param 2, param 3) IMessage TypeDMessage(param 1) ...

Factory Method Implementation

I was going through the 'Factory method' pages in SO and had come across this link. And this comment. The example looked as a variant and thought to implement in its original way: to defer instantiation to subclasses... Here is my attempt. Does the following code implements the Factory pattern of the example specified in the link? Pleas...

Is factory method proper design for my problem?

Hello Everyone, here is my problem and I'm considering to use factory method in C++, what are your opinions ? There are a Base Class and a lot of Subclasses. I need to transfer objects on network via TCP. I will create objects in first side, and using this object I will create a byte array TCP message, and send it to other side. On t...

Smalltalk equivalent of a factory method?

Are factory methods used in Smalltalk, and if so, how should one go about writing one, as opposed to how they would in Java, for example? Thanks. ...

method factories which take class attributes as parameters

I'm finding it useful to create "method factory functions" that wrap a parametrized object attribute in some logic. For example: """Fishing for answers. >>> one().number_fisher() 'one fish' >>> one().colour_fisher() 'red fish' >>> two().number_fisher() 'two fish' >>> two().colour_fisher() 'blue fish' """ class one(object): def n...

Factory method anti-if implementation

Hello all, I'm applying the Factory design pattern in my C++ project, and below you can see how I am doing it. I try to improve my code by following the "anti-if" campaign, thus want to remove the if statements that I am having. Any idea how can I do it? typedef std::map<std::string, Chip*> ChipList; Chip* ChipFactory::createChip(cons...

Using static factory classes to generate GUI components - How and where to add the required listeners?

I would like to use factory classes and methods to generate GUI components, but I don't know how and in which class the various listeners should be declared and added to the components. If I have a simple factory class such as that listed below should I add an ActionListener to the button before it is returned to the calling class. If t...

Can anyone spot the issue with this VB.Net code?

I'm writing some code in VB.Net which I hope demonstrate to colleagues (not to say familiarise myself a little more) with various design patterns - and I'm having an issue with the FactoryMethod Pattern. Here's my code: Namespace Patterns.Creational.FactoryMethod ''' <summary> ''' This is the Factory bit - the other classes ar...