I'm working on a project with a large existing codebase and I've been tasked with performing some re-engineering of a small portion of it. The existing codebase does not have a lot of unit testing, but I would like at least the portion I'm working on to have a full suite of unit tests with good code coverage.
Because the existing codeb...
Currently I have a method that acts as a factory based on a given String.
For example:
public Animal createAnimal(String action)
{
if (action.equals("Meow"))
{
return new Cat();
}
else if (action.equals("Woof"))
{
return new Dog();
}
...
etc.
}
What I want to do is avoid the entire if-...
i am using a factory function (which has grids within windows called using button handler)within one form.
so when i click the button and open a grid and than close it,it works correctly,
but say for example in a situation:
if i open both grids and close , and than try to open other grid the previous grids contents are loaded,but as...
I have a hierarchy of class templates. At the top of the hierarchy is an abstract base class (interface). I won't know which concrete implementation to instantiate until runtime, so it seems like the perfect situation to use the factory pattern. However, virtual member function templates are not allowed in C++.
How can I achieve a le...
In looking at some code reflected from the WCF libraries, I'm seeing a pattern used to create exceptions:
if(argument == null)
{
throw Error.ArgumentNull("argument");
}
Null arguments being the simplest example, with other types of exceptions available through the static error class.
What is the value of this factory pattern? Why...
I am using a custom class based off RelativeLayout but it obviously doesn't render in the Eclipse layout editor.
I have found this article regarding LayoutInflater.Factory and it sounds like what I need to be doing but I can find no guides to using LayoutInflater.Factory.
http://www.macadamian.com/blog/post/android_-_custom_classes_fro...
Hi,
I'm currently implementing the Factory design pattern in Python and I have a few questions.
Is there any way to prevent the direct instantiation of the actual concrete classes? For example, if I have a VehicleFactory that spawns Vehicles, I want users to just use that factory, and prevent anyone from accidentally instantiating Car...
I was playing with creating a generic factory as follows:
trait Factory[T] { def createInstance():T = new T() }
val dateFactory = new Factory[Date](){}
val myDate = dateFactory.createInstance()
The 'new T()' doesn't compile, as T is undefined until runtime. I know that I can get it to work by passing in an instance of the class to so...
Is it wrong to call a class a FooFactory if it doesn't always create Foo objects? For example if I have the following interface:
public interface IFooFactory
{
Foo Create();
}
and implement it as follows:
public class FooFactory : IFooFactory
{
public IFoo Create()
{
return ServiceLocator.Current.GetInstance<IFoo>...
I used 101 samples of Rx Framework ( http://rxwiki.wikidot.com/101samples#toc47 ) last example and created a class like below and usage like in the test function.
private void Test()
{
var order = new Order();
order.ObservableOrder.Subscribe(
ord => Console.WriteLine("Order progress "), // subscribe to onnext event
...
I'm trying to load an ActiveX COM object into a .NET project. It uses licensing (ie FACTORY2). Things work fine on the development machine since the Design License is available. But of course I need to se the runtime license so it will load on other machines.
I'm stuck on how to set the runtime license. I have imported the COM object ...
I've seen examples of this where an interface is provided to a factory and it generates objects that implement the interface. This isn't that complicated to me, but what I don't get is how that can be used to implement behavior.
Take for example the ChannelFactory in WCF... when you generate a channel from an interface it exposes met...
Hi,
I'm not really sure to understand completely the factory pattern.
Let's say I have a class Customer which has basically the following methods:
CreateCustomer - static, creates a customer from scratch and adds it to the database,
LoadCustomer - static, loads an instance of a Customer from the database,
KillCustomer - not static, r...
I have the following code:
def f(cls, value):
# cls is a class
# value is a string value
if cls == str:
pass # value is already the right type
elif cls == int:
value = int(value)
elif cls == C1:
value = C1(value)
elif cls == C2:
value = C2(value)
elif cls == C3
# in this case, we convert the string into...
How do I make sure that a certain class is only instantiated by a factory and not by calling new directly?
EDIT: I need the factory to be a separate class (for dependency injection purposes) so I can't make it a static method of the class to be instantiated, and so I can't make new private.
...
Hi,
I am developing a C++ application used to simulate a real world scenario. Based on this simulation our team is going to develop, test and evaluate different algorithms working within such a real world scenrio.
We need the possibility to define several scenarios (they might differ in a few parameters, but a future scenario might als...
The below code is a factory class that is delivers objects of type IGraph that have the GraphTypeAttribute implemented. Inside the static constructor of the GraphFactory, a list is built by using Linq to collect the appropriate classes to be delivered by the Factory. Normally without Linq I had a buch of loops and if-then's that could be...
I am stuck into resetting an android device to factory. This happens when Unlock pattern is set.
ICheckinService service = ICheckinService.Stub.asInterface(ServiceManager.getService("checkin"));
This line of code returns 'null'. So a dialog showing an error message "No reset was performed because the System Clear service is not availa...
Howdy!
I am trying to write a simple program using Twisted framework and I am struggling with resolving (or even with imaging how to write it) issue I couldnt find any relevant documentation for:
The main reactor uses two factories, one custom, listening for TCP connections on given port (say, 8000) and second one, to log into given IR...
I am trying to create a class that uses a factory to find the right class and then calls methods on that class.
I am doing something wrong though because the intellisense in Visual Studio keeps alerting me to errors and when I try to access the methods that should be within the class the factory returns they are not available.
Can anyon...