I don't have a lot of experience with the factory pattern and I've come across a scenario where I believe it is necessary but I'm not sure the I've implemented the pattern correctly and I'm concerned about the impact it's had on the readability of my unit tests.
I've created a code snippet that approximates (from memory) the essence of ...
does a factory just return an implementation of an interface?
Is that the job?
...
I am trying to create a web-based tool for my company that, in essence, uses geographic input to produce tabular results. Currently, three different business areas use my tool and receive three different kinds of output. Luckily, all of the outputs are based on the same idea of Master Table - Child Table, and they even share a common Mas...
Right now, I've got a switch statement which is being used to create objects based on a string. There are three types of objects which extend an abstract generic object. I should really be using a factory pattern, which I'm figuring out right now. My issue is thus: I appreciate the flexibility of the factory pattern, but right now I'm st...
Hi.
I need some help with DLL architecture / design patterns / OO.
I have been learning about class factory design patterns as a
solution to my current challenge and could use some feedback
at this point.
I have three classes that are custom wrappers for ASP.NET 2.0's
ProfileProvider, MembershipProvider, and RoleProvider.
I'd li...
I've got a factory method inside a parser. Essentially as I load a token I look up the handler for that token, or drop through to the default handler. I've implemented this as a switch and as a Dictionary<string,Type> but both approaches require me to store the mapping somewhere else than the handler class.
We are using Ninject for IOC ...
I have encountered various classes that don't allow creation of their instance directly. Rather we have to create their instance from some other class's static method or it own static method. For example:
B b = A.getB();
or
B b = B.getInstance();
What reason is behind that?
Why don't they allow creating instance directly, as in:
...
The Singleton and the Registry patterns were very simple and easy for me to understand right away but the Factory pattern has been something I haven't been able to get my brain to interpret 100% yet. I think I might understand it now, I have wrote a sample code below, please review and tell me if this is the proper use of the Factory pa...
I have this wcf method
Profile GetProfileInfo(string profileType, string profileName)
and a business rule:
if profileType is "A" read from database.
if profileType is "B" read from xml file.
The question is: how to implement it using a dependency injection container?
Mark Seemann author of book "Dependency injection in .net" Sugge...
In the book Domain Driven Design, by Eric Evans, in Chapter 6 in the section on "Factories" (page 139) it says the following:
"The two basic requirements for any good FACTORY are:
...
"2. The FACTORY should be abstracted to the type desired rather than the concrete class(es) created."
Could you please elaborate on what is meant by t...
I'm using subsonic2's generated classes and wanting to add a layer of abstraction for testing, I created a basic interface, as such...
public interface IController<TCollection>
where TCollection : class
{
TCollection FetchAll();
TCollection FetchByID(object id);
TCollection FetchByQuery(Query query);
bool Delete(obj...
What I would like to do is have a static factory function that you give it a series of attributes and it returns an object that is of a previously undeclared class that extends a known class.
Basically:
<?php
class foo{
public $a;
function increment($b = 1){
$this->a += $b;
}
}
function factory($name, $a){
//returns an ob...
Hi,
I want to implement a Mesh class for a CG project, but have run into some problems.
What I want to do is a Mesh class that hides implementation details (like loading to a specific API: OpenGL, DirectX, CUDA, ...) from the user. Additionally, since the Mesh class will be used in research projects, this Mesh class has to be very flexi...
Hi all-
I am working with a site that will be pulling down feeds from a lot of different sources, and then saving those streams into a common model, in this case a trait. An example of the code from within the FeedEntry class might be:
feed = Feedzirra::Feed.fetch_and_parse(feed_url)
add_entries(feed.entries)
...
def self.add_entrie...
I seem to be mentally stuck in a Flyweight pattern dilemma.
First, let's say I have a disposable type DisposableFiddle and a factory FiddleFactory:
public interface DisposableFiddle : IDisposable
{
// Implements IDisposable
}
public class FiddleFactory
{
public DisposableFiddle CreateFiddle(SomethingThatDifferentiatesFiddles s...
I want to design the file storage part of my application with some flexibility, so one can store files in either S3 or on the web server's hard drive.
I also want this to be flexible on a per user basis, so in their user settings they can choose if they want their files stored in S3 or on the servers file system.
I am thinking of somet...
I am open to other IoC containers, such as NInject and StructureMap if they are much cleaner than this. I hear that StructureMap just introduced "containers" that may simplify this , perhaps?
As the title says, is there a better way? This seems like a lot of code, just to register an object that requires a factory to create it.
// Th...
I just read Factory Method. I understand that it provides a way to delegate the instantiation to sub-classes. But I couldn't understand the possible uses in a real-world scenario.
Can anyone give one typical example showing how Factory method pattern can be used so that I can relate to what I have read.
A problem statement for which fa...
I've been thinking about starting a new project in C#.NET (4.0RC) for a couple of days now. The end result of the project would be a class-library consisting of what I for now call a "ProviderFactory", a couple of interfaces (or abstract classes) and a default "ProviderType" or two.
First of all I might need/decide to change the naming ...
I have a factory class to build objects of base class B.
The object (D) that uses this factory receives a list of strings representing the actual types.
What is the correct implementation:
the factory receives an Enum (and uses switch inside the Create function) and D is responsible to convert the string to Enum.
the factory receives a...