Dependency Injection and Unit of Work pattern?

Okay, I see. What about this: $user = new User; $monitoredUser = new Monitor( $user ); //at update in class Monitor: Monitor::markDirty( $this ) Now you use the Monitor as a decorator; it adds a shell around the user object or any other object that handles incoming requests. If an object gets updated it will be marked dirty by the monitor, however because the Monitor uses a static method for this it remains within the current class scope thus avoiding recursion.

Okay, I see. What about this: $user = new User; $monitoredUser = new Monitor( $user ); //at update in class Monitor: Monitor::markDirty( $this ); Now you use the Monitor as a decorator; it adds a shell around the user object or any other object that handles incoming requests. If an object gets updated it will be marked dirty by the monitor, however because the Monitor uses a static method for this it remains within the current class scope thus avoiding recursion.

That's an interesting angle, although it might make the API a bit more difficult as a result - having to update Monitor manually. Ideally you just want to get a User from the ORM, change it's properties and it automatically gets monitored. The implementations of UoW I've seen use static (external) calls - but that's bad right?

– sunwukung Jun 12 '10 at 12:18 You can also use reflection for this; implement a __call() method that routes the request to User in case an accessor has been invoked. – Gabor de Mooij Jun 12 '10 at 13:39 Maybe for inspiration: I have proposed an alternative UoW pattern: gabordemooij. Com/unit_of_work, and I have my own ORM as well: redbeanphp.Com – Gabor de Mooij Jun 12 '10 at 13:41 I'm accepting this answer - it's shown me the alternative I was looking for.

I think for simplicity it might serve my personal objectives to use a static call - but I've got a better idea of the implications of each approach now. Thanks for your help – sunwukung Jun 12 '10 at 19:38.

Thought I never did it, your Monitor class seems to correspond to an "Observer" design pattern. This way you don't have to ask the Monitor class to mark the class as dirty, but it should do it alone. As I said I never did it in PHP but i'm pretty confident that you can look on Google a way to implement this design pattern in PHP.

Sure, this is basically the same as using a setter. My only issue is that it sets up a recursion loop (since a reference to the Entity resides in the Monitor, and a reference to the Monitor resides in the Entity). – sunwukung Jun 10 '10 at 14:58.

Big question is; what happens inside markModified()..? I copied to code and tried it, but I don't get the error you reported. So I guess one piece of puzzle is missing?

MarkModified simply stores a reference to $this to the $_modified array in Monitor. It's not an error, but a flag in FirePHP - if Monitor contains a ref of Entity, and Entity contains a ref of Monitor, it's a kind of recursion – sunwukung Jun 11 '10 at 20:14.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions