OO - Question

  • Thread starter Thread starter Lee
  • Start date Start date
L

Lee

Hello all,

Please excuse me if this is not the right group to ask in.

Assume that I have a Person object that reflects data held in a
datastore (DB, XML FIles, etc). Gernally, where should the job of
populating that object be bound?

Should code that instantiates the object fill it?

Should the object populate itself by having a datastore object handed
to it in it's constructor?

Thank you,

--
Warm Regards,
Lee

"Upon further investigation it appears that your software is missing
just one thing. It definitely needs more cow bell..."
 
Lee said:
Hello all,

Please excuse me if this is not the right group to ask in.

It probably isn't, but I'm sure you will get a number of answers here.
Its a reasonable question in any language.
Assume that I have a Person object that reflects data held in a
datastore (DB, XML FIles, etc). Gernally, where should the job of
populating that object be bound?

I would use a set of three objects, myself:

1) The object that stores the information in memory (i.e. Person).
2) The interface to the database (any DB sort of object that contains
table info)
3) An object to take information from the database and store it in the
Person object.

Reasoning:

1) A person remains the same no matter what the underlying
representation is.
2) The database remains the same, or at least its interface does, no
matter what
is done with the database.
3) The translation object can be modified without either other object
being aware
of any changes (i.e., suppose that you need to change a data type).

Matt
 
Matt enlightened me by writing:
It probably isn't, but I'm sure you will get a number of answers here.
Its a reasonable question in any language.


I would use a set of three objects, myself:

1) The object that stores the information in memory (i.e. Person).
2) The interface to the database (any DB sort of object that contains
table info)
3) An object to take information from the database and store it in the
Person object.

Reasoning:

1) A person remains the same no matter what the underlying
representation is.
2) The database remains the same, or at least its interface does, no
matter what
is done with the database.
3) The translation object can be modified without either other object
being aware
of any changes (i.e., suppose that you need to change a data type).

Matt

So, you're saying you would recommend using a kind of "adapter" to
populate the object, right?

I guess than that a base class of "populator" should be created and
extended for each object type...?

--
Warm Regards,
Lee

"Upon further investigation it appears that your software is missing
just one thing. It definitely needs more cow bell..."
 
I guess than that a base class of "populator" should be created and extended for each object type...?

Only if you find while designing or coding that there is common code
between the various adapters. Sometimes it's better to start out just
writing classes and then refactor later. The only time I start out with
a base class is if, during design, I can see the pattern already and
recognize the need for one.
 
Lee said:
Matt enlightened me by writing:


So, you're saying you would recommend using a kind of "adapter" to
populate the object, right?
Correct.


I guess than that a base class of "populator" should be created and
extended for each object type...?


Hm. It could. It really depends on what you are going to accomplish.
Realize
that you don't have all the answers up front, and go with what works.
You can
then fix it, as long as you haven't made things too interdependent,
later on.
Yes, its heresy, but then, its also realistic.

Matt
 

Ask a Question

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.

Ask a Question

Similar Threads


Back
Top