tags:

views:

91

answers:

4
+3  A: 

A helper class that contains only the logic to fill the object

is called a Factory Class. It seems that this is what you need.

Also, take a look at Dependency Injection.

bruno conde
+1  A: 

Where does this information come from? Is it hardcoded/consistent? Use the Object's constructor. Is it variable or does it come from a datastore? Use the DAO pattern.

BalusC
it comes from a DataStore.
EugeneP
Here's a kickoff tutorial about the DAO pattern: http://balusc.blogspot.com/2008/07/dao-tutorial-data-layer.html
BalusC
+1  A: 

Joshua Bloch discusses Static Factories and the Builder pattern in this excerpt from the second edition of his book Effective Java.

trashgod
It seems to me that you answered my question. But it proves that the extraction/getting a reference logic should stay within the object. Is that true?
EugeneP
Yes, in the sense that the cited patterns are ways to impose an internally consistent object state. The manner in which this is achieved is an implementation detail. As your source is a DataStore, the DAO pattern suggested by BalusC is a way to minimize the coupling mentioned in your original question.
trashgod
A: 

Regarding your last phrase: 'So I can call it a factory, but would it really be what they called "A Factory pattern"?'
IMHO, patterns are just food for thought. Don't worry too much if whatever you're doing fits the exact textbook definition (which is disputed anyway) or not. :-)

Eli Acherkan
Agree. good comment.
EugeneP