Re: enterprise patterns headache

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 13 Apr 2005, Richard Lynch wrote:

On Wed, April 13, 2005 2:01 pm, Robert Janeczek said:

I can't claim a detailed understanding of what you are doing, and,
frankly, it sounds like you are creating a BUNCH of over-engineered
headache-inducing code without a good, proven need for it.  YMVV.

The Upper Case Nice Names I used before are not really difficult to implement. Some of these patterns are even smaller than most implementations of GOF design patterns.


That said, one thing I *did* understand and can comment on:

Sample code:
$company = CompanyMapper::find(1); // we have ghost inside $company
//some other operations, but we don`t touch $company
$company2 = CompanyMapper::findByName('Big Ltd.');

Now let`s assume, that company with ID=1 has name Big Ltd. We have two
independent copies of the same object what kinda sucks :] The problem is
that both finding methods return ghosts and the second one doesn`t know
his ID yet. If there would be only ID-based searching than Identity Map
would detect it and caused returning the same instance, but it`s not...

So why not do this: Make findByName look up the $ID with the query you already use, possibly caching the other fields/data you use frequently in some kind of very temp space: $row (array returned from query). Then call CompanyMapper::find($ID, $row); which uses the info it already has given for free in $row, but can also check your cache of existing object, fill in any free data from $row, and return the existing object if it's there.

The problem is that both finding methods don`t query the database when they are called. They just store information how can the database be queried to fetch the data which should be inside them. So - I don`t have ID inside $company2 unless I accessed it`s variables.


Perhaps a specialized object that manipulates/returns other objects based
on arguments is in order.  Instead of a zillion objects that all do that
same thing, only one for each real object, you have one that handles all
the other objects the same way, but trying to find the same object in your
cache first, then digging deeper into lazy load (or whatever) to build it.

That`s what Identity Map doing - it keeps track of all business objects inside application. Still - after doing find*() there is no way to tell that two variables are the same object inside until they are accessed. And after they are accessed it`s already to late, because we have two instances.


How certain are you that all this code is saving you *ANYTHING*?

Quite much :) Honestly - it`s a pleasure to write code for application using this architecture. Repetition of code is basicly non-existent, except for interfaces (which are generated automaticly anyway).


Is it worth the development/maintenance expense?

The expenses are not really high. The biggest problem is that if come to dead end somewhere than we have to look for solutions in java literature :] And of course it takes time for PHP developer to switch to using it, but that`s not different from any framework.


It`s worth the effort, trust me :)

rash

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux