I'm working on an internal project for my company, and part of the project is to be able to parse various "Tasks" from an XML file into a collection of tasks to be ran later.
Because each type of Task has a multitude of different associated fields, I decided it would be best to represent each type of Task with a seperate class.
To do t...
Hi,
When is it a good idea to use factory methods within an object instead of a Factory class?
Regards,
-jj.
...
There's something very unsatisfactory about this code:
/*
Given a command string in which the first 8 characters are the command name
padded on the right with whitespace, construct the appropriate kind of
Command object.
*/
public class CommandFactory {
public Command getCommand(String cmd) {
cmdName = cmd.subString(0,8)....
Our team is looking to switch from using mbunit to mstest, but there appears to be some disconnect between the two.
Does anyone know how to simulate the CombinatorialTest and Factory attributes from mbunit when using mstest?
I think that is our only stumbling block before doing the switch.
...
Hello, im creating a Factory class that will contruct and return an object. I normally would do all of the data stuff at the Data Access Layer, but i dont think i could reach my objective and still do so. What i want to do is use a SQLDataReader to quickly read the data information and populate the object to be returned from the factor...
I have a factory class that populates objects with data. I want to implementing saving from the object, but do not want to populate the object with db stuff - is it stupid to have my Factory that creates the class also save the data?
ie: in my .Save() method on the object i would call Factory.Save(myObject);
...
I am still trying to wrap my head around design patterns and for the second time I'm coming up against the same problem that seems to be crying out for a pattern solution.
I have an accounts system with multiple account types. We have restaurant, hotel, service_provider, and consumer account types. Im sure there will be more business a...
When returning objects from a class, when is the right time to release the memory?
Example,
class AnimalLister
{
public:
Animal* getNewAnimal()
{
Animal* animal1 = new Animal();
return animal1;
}
}
If i create an instance of Animal Lister and get Animal reference from it, then where am i supposed to delete it?
int ...
What's a more elegant way of having the code below where i want to return a derived class based on the type of another class.
if (option_ is Rectangle)
{
modelInputs = new Foo();
}
else if (option_ is Circle)
{
modelInputs = new Bar();
...
I'm working on a quick project to monitor/process data. Essentially that's just monitors, schedules and processors. The monitor checks for data (ftp, local, imap, pop, etc) using a schedule and sends new data to a processor. They call have interfaces.
I'm trying to find a sane way to use config to configure what schedule/processor each ...
Hi,
I need to implement the classic Factory Method pattern in ASP.NET to create server controls dynamically.
The only way I've found to create .ascx controls is to use the LoadControl method of the Page/UserControl classes. I find it messy however to link my factory with a page or to pass a page parameter to the factory.
Does anybody ...
I've been thinking of ways of providing syntactic sugar for a framework I have been working on. I want to deal with Immitable objects exclusively.
Say I have an immutable object and wish to create a modified version of it. Would, in your view, a non-instantiable class with a single static factory method break OO principles ?
As an...
Hi
I am just getting started with IoC containers so apologies if this is a stupid question.
I have code like the following in an app
internal static class StaticDataHandlerFactory
{
public static IStaticDataHandler CreateHandler(StaticDataUpdate staticDataUpdate)
{
if (staticDataUpdate.Item is StaticDat...
In short: what is the best way to design and implement a factory+plugin mechanism, so that plugins can replace objects in the main application.
We have a code base from which we build our applications. The code base is fine for 70-95% of the applications, meaning that in each new application we need to change 5-30% of the default behavi...
I am working on an object factory to keep track of a small collection of objects. The objects can be of different types, but they will all respond to createInstance and reset. The objects can not be derived from a common base class because some of them will have to derive from built-in cocoa classes like NSView and NSWindowController.
I...
I'm aiming to create a set of objects, each of which has a unique identifier. If an object already exists with that identifier, I want to use the existing object. Otherwise I want to create a new one. I'm trying not to use the word Singleton, because I know it's a dirty word here...
I can use a factory method:
// A map of existing ...
Hi,
I'm looking at the new object initializers in C# 3.0 and would like to use them. However, I can't see how to use them with something like Microsoft Unity. I'm probably missing something but if I want to keep strongly typed property names then I'm not sure I can. e.g. I can do this (pseudo code)
Dictionary<string,object> parms = new...
In my application, there are 10-20 classes that are instantiated once[*]. Here's an example:
class SomeOtherManager;
class SomeManagerClass {
public:
SomeManagerClass(SomeOtherManager*);
virtual void someMethod1();
virtual void someMethod2();
};
Instances of the classes are contained in one object:
class TheManager {
pub...
I have a c# struct where I need to forbid calling the no args constructor on it.
MyStruct a;
/// init a by members // OK
MyStruct b = MyStruct.Fact(args); // OK, inits by memebers
MyStruct s = new MyStruct(); // can't have that
I'm doing this mostly to force explicet values for all members as there are no valid default values and a...
Is it a good idea to have a factory class using generics to instantiate objects?
Let's say I have a class Animal and some subclasses (Cat, Dog, etc):
abstract class Animal
{
public abstract void MakeSound();
}
class Cat : Animal
{
public override void MakeSound()
{
Console.Write("Mew mew");
}
}
class Dog : Ani...