Decoupling musing
- From: "VisionSet" <spam@xxxxxxxxxxxx>
- Date: Sun, 20 Nov 2005 17:44:51 GMT
Not seen this done but it stikes me as a approach that may have some merit.
Often a class needs to know nothing concrete about the object it is calling
methods on.
However sometimes such a class needs to instantiate this very object and yet
not care so long as it implements interface X.
So why not pass in a Class object that implements X, and do
class.newInstance()
public X createAndProvideAUsefulX(Class<? extends X> myClassOfX) {
X x = myClassOfX.newInstance();
x.doWork(blah);
return x;
}
--
Mike W
.
- Follow-Ups:
- Re: Decoupling musing
- From: Roedy Green
- Re: Decoupling musing
- From: Daniel Dyer
- Re: Decoupling musing
- Prev by Date: Re: Why the name of a file that contains java code should be same as the name of the class that is contained init?
- Next by Date: Re: Best Java ever
- Previous by thread: Main Menu (switch help)
- Next by thread: Re: Decoupling musing
- Index(es):
Relevant Pages
|