factory

Can/should I use a mocking framework to dynamically add events to a class?

Consider the following interface: public interface IMyCallback { void SomeEvent(int someArg); } which is the contract for a WCF callback that will be receiving "events" from a WCF service. My implementation for this interface looks like this public class MyCallback : IMyCallback { void IMyCallback.SomeEvent(int someArg) { O...

How does a factory know which type of object to create?

I believe the factory method design pattern is appropriate for what I'm trying to do, but I'm not sure how much responsibility (knowledge of subclasses it creates) to give it. The example of using the factory method pattern at Wikipedia describes the situation I'm in almost exactly: public class ImageReaderFactory { public static ...

Service Factory for VS 2008

Hi All Any one can please help me how to use the service factory for the VS 2008. What are all the tools need to install. Thanks in Advance Sekar ...

How to design my classes to leverege factory and be extensible?

My c++ SOA app has a concept of "session" that is used exchange data between services. In example its used for checking legality of some service A operations before executing session B which commits or rollback changes. Whatever. I have 2 types of session modes: normal and what-if. Going further, I have different session, session for le...

Factory method pattern in java using generics, how to?

I have code that looks like follows: public interface BaseDAO{ // marker interface } public interface CustomerDAO extends BaseDAO{ public void createCustomer(); public void deleteCustomer(); public Customer getCustomer(int id); // etc } public abstract class DAOFactory { public BaseDAO getCustomerDAO(); public static DAOFactory getIn...

Passing arguments to a specific subclass, through a factory method

Let's say I have an abstract class Drink, and a factory method which chooses the type of Drink (Wine, Beer, etc.) to create at runtime. Each Drink needs some arguments to properly initialize itself. Some of these are common to all Drinks; for example, they might all require a DrinkConfig argument. But each Drink may have its own unique...

webform linq to sql and repository pattern sample project

can anyone provide a webform linq to sql and repository pattern sample project link ...

Factory for Callback methods - Python TKinter

Writing a test app to emulate PIO lines, I have a very simple Python/Tk GUI app. Using the numeric Keys 1 to 8 to simulate PIO pins 1 to 8. Press the key down = PIO High, release the Key = PIO goes low. What I need it for is not the problem. I kind of went down a rabbit hole trying to use a factory to create the key press call back funct...

Cost of Reflection while using factory

Good people of stackoverflow, As always, I am writing a factory in order to dynamically instantiate objects. To schematize, I have four types: class CatDescriptor : PetDescriptor class DogDescriptor : PetDescriptor class Cat : Pet class Dog : Pet I instanciate the two last types from the factory. And here comes the dilemma: Should ...

Can I have Hibernate create an object through factory method?

Is there a way to map a factory method in Hibernate (as opposed to having Hibernate call a default constructor and reflectively set properties or fields)? And if it can't be mapped, does Hibernate provide a hook for custom object creation on a class by class basis? Thanks! ...

Is it still considered a Factory if the objects being returned by the factory are static?

When my application starts up it needs to get an instance of the correct DAL class (currently there are 4) based on what user is logged in. Certain users are pulling down from certain databases. Is it still considered a "factory" pattern if instead of instantiating instances of those DAL classes, I simply return the correct static inst...

Does a framework like Factory Girl exist for Java?

Factory Girl is a handy framework in rails for easily creating instances of models for testing. From the Factory Girl home page: factory_girl allows you to quickly define prototypes for each of your models and ask for instances with properties that are important to the test at hand. An example (also from the home page): Factory....

Where to place a getAll() method when having a Factory

I'm doing a java application. This are my files so far: Person Interface. has a setName(String aName) method PersonImpl Implementation of Person Interface. PersonFactory Interface has a createPerson() PersonFactoryImpl Implementation of PersonFactory Interface. The thing is I was willing to add a method getAll() that returns a ...

Is there a way to use a class as a class factory for user controls?

Is there a way in .NET 2.0 to use a class as a class factory for user controls? In other words, 1 super that sits there and when I want a user control, it creates it and returns it to me. It seems it needs the ASP namespace which I can't seem to get it to reference. I have a masterpage with a placeholder. Depending upon the user's authe...

The "Self-Factory" Pattern

I don't know if there is an official name for this, but I have been playing with what I like to call the "self-factory" pattern. Basically, it's when an abstract base class acts as a factory for itself. Let me explain: I have Foo objects and Bar objects in my system, which are used via interfaces FooInterface and BarInterface. I need...

How do you override :set_initial_state from AASM when testing with Factory Girl factories?

Update Answered below. In case the linked site disappears, you can use mocha to stub the initial state and prevent overwriting as in ... require 'mocha' class OrderTest < ActiveSupport::TestCase def setup Order.any_instance.stubs(:set_initial_state) @order = Factory(:order, :state => "other_state") end ... end Origina...

Unit testing factory methods which have a concrete class as a return type

So I have a factory class and I'm trying to work out what the unit tests should do. From this question I could verify that the interface returned is of a particular concrete type that I would expect. What should I check for if the factory is returning concrete types (because there is no need - at the moment - for interfaces to be used)...

How can I combine the factory pattern with code flexibility

I am considering a factory function to create different classes in the same hierarchy. I understand that normally a factory is normally implemented as follows: Person* Person::Create(string type, ...) { // Student, Secretary and Professor are all derived classes of Person if ( type == "student" ) return new Student(...); if ...

Generic factory

Hi all, suppose I have a TModel: TModelClass = class of TModel; TModel = class procedure DoSomeStuff; end; and 2 descendants: TModel_A = class(TModel); TModel_B = class(TModel); and a factory : TModelFactory = class class function CreateModel_A: TModel_A; class function CreateModel_B: TModel_B; end; Now I want to refactor...

Factory Creating Objects According to a Generic Type C#

What would be the most efficient way to instanciate an object according to a generic type passed to a Factory class, for instance: public class LoggerFactory { public static ILogger<T> Create<T>() { // Switch Statement? // Generic Dictionary? // EX.: if "T" is of type "string": return (ILogger<T>)new Stri...