Is there a way to modify the class being constructed in a constructor?
public class A {
A() {
//if (condition) return object of type B
//else return A itself
}
}
public class B extends A { }
Basically I want to use the base class constructor as a factory method. Is it possible in java?
...
I am working on implementing a non web.config approach of WCF services using the factory attribute on the .svc file per Rick Strahl's blog post:
Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory"
Locally, I am running IIS7 in Visual Studio 2008 and have no problem, but when I deploy to my web server (currently running...
What is the slickest, most Ruby-like way to have a single constructor return an object of the appropriate type?
To be more specific, here's a dummy example: say I have two classes Bike and Car which subclass Vehicle. I want this:
Vehicle.new('mountain bike') # returns Bike.new('mountain bike')
Vehicle.new('ferrari') # returns C...
When to use Factory method pattern?
Please provide me some specific idea when to use it in project?
and how it is a better way over new keyword?
...
In Karl Seguin's Foundations of Programming there is a small section on using the factory pattern. He closes the passage by stating "you can accomplish the same functionality with constructor overloading", but doesn't indicate when or why?
So,when does it make more sense to use the factory pattern rather than an overloaded constructor ...
I have a question about the usage of "utility/helper" methods in a factory class. Consider an example of an XML string that reprents a document. I have a class that transforms it to an "object" (say PDF, Word, CSV, etc.). I have a factory class (lets call it DocumentFactory) that accepts this XML string and based on certain rules gives b...
Hi all-
I have a user class, where I am trying to attach a profile created by a factory. Here is the class:
class User < ActiveRecord::Base
acts_as_authentic
has_one :profile
after_create {self.profile = ProfileFactory.create_profile(self.role)}
end
and the factory looks like this
class ProfileFactory
def self.create_pr...
I cant seem to grasp the proper concepts of a factory.
Can anyone help me code a simple test? I read some texts over the internet and cant code it the same way. Actually i cant understand the process. Copying code is easy, but i need to learn why this wont work.
class Factory:
def __init__(self):
self.msg = "teste"
de...
Short question: If I have class that impelemnts FactoryBean interface, how can I get from FactoryBean object itself instead of FactoryBean.getObject()?
Long question: I have to use 3-rd party Spring based library which is hardly use FactoryBean interface. Right now I always must configure 2 beans:
<!-- Case 1-->
<bean id="XYZ" class="F...
This is a dirty thing to do, and I feel dirty for doing it:
public abstract class InterestRate {
// irrelevant details
public static T ImpliedRate<T>(
double factor,
double time,
DayCounter dayCounter
) where T : NonCompoundedInterestRate {
MethodInfo methodInfo = typeof(T).GetMethod(
...
Hello, I'm working on a game and am trying to implement a smart way to create npc-objects in C++ from parsing a text file.
Currently this is hard coded in a Factory-object. Like this:
IActor * ActorFactory::create(string actortype, Room * r, string name, int hp)
{
if(actortype == "Troll")
{
return new Troll(r, name, hp);
...
I've created a factory assembly that can process any type of transaction (that supports ITransactionType). I can add more transaction types in separate assemblies, all of which will work with the factory without it needing to be recompiled (which is one of the benefits of a factory).
There is an actual list of transaction types that ca...
My understanding of a factory is that it encapsulates instantiation of concrete classes that all inherit a common abstract class or interface. This allows the client to be decoupled from the process of determining which concrete class to create, which in turn means you can add or remove concrete classes from your program without having t...
I am new to domain driven development & have a simple question. If a service needs to generate some entity as a response to an operation then how should it be done? One of the ways is to inject entity factory in the service instance. Is there any other better solution for the same ?
Thanks & regards
...
The documentation for Autofac has an interesting page describing its ability to automatically generate delegate factories. It also strongly suggests that you can get similar results without Autofac by writing them by hand.
I'm using Unity for IoC and would like to avoid passing the container around to objects that need to create other o...
hi
I have have a factory class, which needs to instantiate several templates with consecutive template parameters which are simple integers. How can I instantiate such template functions without unrolling the entire loop?
The only thing that can think of is using boost pre-processor. Can you recommend something else, which does not d...
Short summary: When you want to predefine certain instantiations of a class, is it better to create subclasses or a factory?
Problem Context
I have a view helper class MyWebserviceUrl that has a bunch of properties. It's purpose is to generate an url.
I would like to be able to have preconfigured instances of this class, so that I do...
Given a class:
class TCurrency {
TCurrency();
TCurrency(long);
TCurrency(const std::string);
...
};
Wrapped with Boost.Python:
class_<TCurrency>( "TCurrency" )
.def( init<long> )
.def( init<const std::string&> )
...
;
Is it possible to create a factory method that appears as a constructor in Python:
...
The following python module is meant to be a basis for "constant" handling in python. The use case is the following:
one groups some constants (basically "names") that belong together with their values into a dictionary
with that dictionary bound to class variable a class is created and instantinated run-time
the attributes of this cla...
So, the object model is rather complex and hierarchical.
Grandfather accepts is created by a GrandfatherFactory that accepts a GrandfatherRepository in it's constructor.
All is well.
Now when Grandfather needs to load it's Children how does it do it?
How does it know about the ChildFactory and ChildRepository? It shouldn't correct?
...