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 ...
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...
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 ...
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 ...
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?
...
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 :...
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:
...
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...
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...
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...
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...
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...
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...
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...
...
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 )
...
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....
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...
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 {
...
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...
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();
...