Hi,
I accidentally posted this message directly to iosonogio, so here's
the copy for all of you. I wish this group engine added proper
Reply-To: header and cleared Disposition-Notification-To: header
automaticly...
iosonogio wrote:
>
>
> Szymon Wilkołazki wrote:
>> Then you have your model doing just Business Logic, and it doesn't
have to care about database logic.
>>
>
>
> Hi,
> this is the way I would like to do.
>
> Here comes the initial problem though.
>
> The dataStore (a Zend_Db_table, an interface, or whatever) used by my
> Business Object now actually uses a Zend_Db to fetch records.
>
> When it fetches a single or a collections of records, ie articles,
I have
> such records in the form of array or stdClass. In the case I use a
Zend_Db_Table dataStore inside my Business Object, I
> would have returned a set of, say, Article_Record (where Article_Record
> extends Zend_Db_Table).
>
> I would need to trasform them (arrays, stdClass or Article_Record),
into
> Article class objects if I want them to have behaviour and actually
be my
> real business object Article.
>
> Hope I explained clearly in the last passage.
>
> How would you manage this ?
>
I am not sure yet, as I said, those was a concept currently developing
in my mind.
Anyway, I would add some methods to my (business model) Article class:
setStore (Article_Record|Other_Source $dataStore); which would set
internal dataStore, and choose proper translation method based on the
$dataStore class.
Two translation methods for each supported dataStore class:
loadFrom{$_storeType} ()
saveTo{$_storeType} ()
two general methods:
load();
save(); - those would check $_storeType and call the above two;
The concrete loadFromArticleRecord would get all the data from record
and set internal properties of Article class. The
saveToArticleRecord() would translate the Article to Article Record.
Anyway, those translation methods would need to know the structure of
ArticleRecord, and possibly should know how to create a Author object
based on the author_id in Article_Record or dependand Author_Record
object. All nuances of translation from records to business objects
should be encapsulated in this two methods.
One could use some Command or Strategy template instead of those
methods, I am just learning templates currently and am not jet sure
how to achieve that with templates.
With this approach, the only place which you need any knowledge of
Article Record are this two methods called when Article is loaded from
data store and when it is saved.
Hope this helps, but keep in mind that this is only my concept which
need some serious thinking before applying to a real project.
Regards,
Szymon Wilkołazki