2010年8月24日星期二

Re: [fw-mvc] Re: Centralized Stack/Broker or something for Models

We've managed to avoid dependency issues by creating an object that uses the Identity Map and Unit of Work patterns. The Identity Map keeps track of all the objects as we pull them from the database so we don't have to worry about duplicating objects. The Unit of Work functions as intermediary between the model and the functions used to retrieve and store data from our data sources. When we call the Unit of Work to do it's thing it goes through the list of objects in the Identity Map and performs any operations which need to be done on the objects. This allows us to create unit tests which test how our model functions and then separately test the methods they are taken from and stored to our data source. Of course, all of this is also completely separate from the controller ensuring we have a thin controller and a fat model.

David Kanenwisher

On Mon, Aug 23, 2010 at 8:59 AM, Hector Virgen <djvirgen@gmail.com> wrote:

It seems a lot of the solutions out there rely in static classes/methods/properties. How does this affect unit testing? And how do you encourage dependency injection with your fellow developers?

--
Hector Virgen
Sent from my Droid X

On Aug 23, 2010 6:52 AM, "Christoph" <christopher@emergencyinhaler.com> wrote:
>
> I set up my model class with a static factory method and a static registry.
> So when I want to grab a user object, I call User::factory($username). The
> factory method will check if this object exists in the registry. If it does,
> return it. If not, instantiate it and store it in the registry. This way
> each user only gets instantiated once. It also keeps the logic in the model
> class itself, and out of the bootstrap and controllers.
>
>
> Marko78 wrote:
>>
>> So I was thinking, am I wasting resources? Declaring the same class over
>> and over again in the same request. Should I have somekind of centralized
>> stack where to register my Models when needed and the next time the Model
>> is needed it could be get from this centralized stack?
>>
>
> --
> View this message in context: http://zend-framework-community.634137.n4.nabble.com/Centralized-Stack-Broker-or-something-for-Models-tp2333975p2335141.html
> Sent from the Zend MVC mailing list archive at Nabble.com.
>


没有评论: