factory

Using fixtures with factory_girl

When building the following factory: Factory.define :user do |f| f.sequence(:name) { |n| "foo#{n}" } f.resume_type_id { ResumeType.first.id } end ResumeType.first returns nil and I get an error. ResumeType records are loaded via fixtures. I checked using the console and the entries are there, the table is not empty. I've found ...

How to generate tests with different names in testng, java?

I'm using testng to run selenium based tests in java. I have a bunch of repeated tests. Generally they do all the same except of test name and one parameter. I want to automate generation of it. I was thinking about using factory. Is there a way to generate tests with different name? What would be the best approach to this? As for now...

Is there a design pattern for this ?

I have a component that needs to call a specific service depending on the input it receives. So my component has to look at the input and based on a configuration that says "for this input call this service with this data" needs to call the proper service. The services have a common signature method and a specific one (each). I thought ...

Can the Singleton be replaced by Factory?

Hello Everyone There are already quite some posts about the Singleton-Pattern around, but I would like to start another one on this topic since I would like to know if the Factory-Pattern would be the right approach to remove this "anti-pattern". In the past I used the singleton quite a lot, also did my fellow collegues since it is so ...

Spring and factory object

I have an abstract class with a static method that returns either one concrete subclass or another, depending on this static method's arguments. How do I define a bean in spring configuration file that will invoke this static method with the arguments? ...

Factory Method pattern and public constructor

Hi, Im making a factory method that returns new instances of my objects. I would like to prevent anyone using my code from using a public constructor on my objects. Is there any way of doing this? How is this typically accomplished: public abstract class CarFactory { public abstract ICar CreateSUV(); } public class MercedesFactory :...

Is there any way to provide custom factory for .Net Framework creation Entities from EF4 ?

There are a lot of posts about how cool POCO objects are and how Entity Framework 4 supports them. I decided to try it out with domain driven development oriented architecture and finished with domain entities that has dependencies from services. So far so good. Imagine my Products are POCO objects. When i query for objects like this: ...

singleton factory connection pdo

Hey guys I am having a lot of trouble trying to understand this and I was just wondering if someone could help me with some questions. I found some code that is supposed to create a connection with pdo. The problem I was having was having my connection defined within functions. Someone suggested globals but then pointed to a 'better' sol...

(static initialization/template instantiation) problems with factory pattern

Why does following code raise an exception (in createObjects call to map::at) alternativly the code (and its output) can be viewed here intererestingly the code works as expected if the commented lines are uncommented with both microsoft and gcc compiler (see here), this even works with initMap as ordinary static variable instead of sta...

Is it possible to create a C++ factory system that can create an instance of any "registered" object type, regardless of inheritance?

Hello, I've spent my entire day researching this topic, so it is with some scattered knowledge on the topic that i come to you with this inquiry. Please allow me to describe what I am attempting to accomplish, and maybe you can either suggest a solution to the immediate question, or another way to tackle the problem entirely. I am tryi...

C++0x class factory with variadic templates problem

I have a class factory where I'm using variadic templates for the c'tor parameters (code below). However, when I attempt to use it, I get compile errors; when I originally wrote it without parameters, it worked fine. Here is the class: template< class Base, typename KeyType, class... Args > class GenericFactory { public: GenericFac...

Populating an association with children in factory_girl

I have a model Foo that has_many 'Bar'. I have a factory_girl factory for each of these objects. The factory for Bar has an association to Foo; it will instantiate a Foo when it creates the Bar. I'd like a Factory that creates a Foo that contains a Bar. Ideally this Bar would be created through the :bar factory, and respect the build st...

How to implement an ID field on a POCO representing an Identity field in SQL Server?

If I have a Domain Model that has an ID that maps to a SQL Server identity column, what does the POCO look like that contains that field? Candidate 1: Allows anyone to set and get the ID. I don't think we want anyone setting the ID except the Repository, from the SQL table. public class Thing { public int ID {get;set;} } Candida...

How to construct objects based on XML code?

I have XML files that are representation of a portion of HTML code. Those XML files also have widget declarations. Example XML file: <message id="msg"> <p> <Widget name="foo" type="SomeComplexWidget" attribute="value"> inner text here, sets another attribute or inserts another widget to the tree if needed... ...

Factory Method Using Is/As Operator

I have factory that looks something like the following snippet. Foo is a wrapper class for Bar and in most cases (but not all), there is a 1:1 mapping. As a rule, Bar cannot know anything about Foo, yet Foo takes an instance of Bar. Is there a better/cleaner approach to doing this? public Foo Make( Bar obj ) { if( obj is Bar1 ) ...

How do you make a Factory that can return derived types?

I have created a factory class called AlarmFactory as such... 1 class AlarmFactory 2 { 3 public static Alarm GetAlarm(AlarmTypes alarmType) //factory ensures that correct alarm is returned and right func pointer for trigger creator. 4 { 5 switch (alarmType) 6 { 7 case AlarmTypes....

Factory Pattern: Determining concrete factory class instantiation?

I'm trying to learn patterns and I'm stuck on determining how or where a Factory Pattern determines what class to instanciate. If I have a Application that calls the factory and sends it, say, an xml config file to determine what type of action to take, where does that logic for interpreting the config file happen? THE FACTORY using S...

Should I use an interface or factory (and interface) for a cross-platform implementation?

Example A: // pseudo code interface IFoo { void bar(); } class FooPlatformA : IFoo { void bar() { /* ... */ } } class FooPlatformB : IFoo { void bar() { /* ... */ } } class Foo : IFoo { IFoo m_foo; public Foo() { if (detectPlatformA()} { m_foo = new FooPlatformA(); } else { ...

The ** idiom in C++ for object construction

In a lot of C++ API'S (COM-based ones spring to mind) that make something for you, the pointer to the object that is constructed is usually required as a ** pointer (and the function will construct and init it for you) You usually see signatures like: HRESULT createAnObject( int howbig, Object **objectYouWantMeToInitialize ) ; -- bu...

What is the benefit of using a factory class in the following code?

Here's the code: SAXParserFactory mySAXParserFactory = SAXParserFactory.newInstance(); SAXParser mySAXParser = mySAXParserFactory.newSAXParser(); Why use that if you can use something more intuitive like: SAXParser mySAXParser = new SAXParser(); ...