R
Raffael Vogler
Hello,
does someone know how to define
a c'tor within an IF and an AC?
best regards
does someone know how to define
a c'tor within an IF and an AC?
best regards
Raffael said:does someone know how to define
a c'tor within an IF and an AC?
Michael said:If you mean "constructor", then it's of course impossible in an interface,
Chris said:Though you _can_ include a factory method as part of an interface;
Except that the methods in an interface can't be static, a static method
can't implement an interface method, and a non-static factory method
is kinda pointless.
Michael said:Except that the methods in an interface can't be static, a static method
can't implement an interface method, and a non-static factory method
is kinda pointless.
Not at all ;-)
public interface Foo { ... }
public interface FooFactory
{
Foo makeFoo();
}
class MyFoo extends Foo { ... }
class MyFooFactory extends FooFactory
{
Foo makeFoo()
{
return new MyFoo();
}
}
class OtherCode
{
private /* maybe static */ FooFactory fooBuilder;
// somewhere, maybe in constructor
fooBuilder = // ...something...
void doSomeWorkThatNeedsAFoo()
{
Foo foo = fooBuilder.makeFoo();
....
}
}
It's a pattern I use every day (since I work mostly in Smalltalk).
Raffael said:Hello,
does someone know how to define
a c'tor within an IF and an AC?
Joona said:
It's also used rather extensively in the JAXP (Java API for XML
Parsing) framework.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.