A PHP secret to understanding Data Mapper Pattern in Fowler’s Patterns of Enterprise Application Architecture (PoEAA)

Here’s a snippet of a Java code example in Fowler’s esteemed  book, Patterns of Enterprise Application Architecture (PoEAA).

(On Page 282 of the 15th Printing - Oct 2009)

——–

class Mapper…

protected DomainObject AbstractFind(long id)  {
…some example code…
}

protected DataRow FindRow(long id)  {
…some example code…
}

public DomainObject Find (DataRow row)  {
…some example code…
}

———–

Ok - I don’t know about you. But when I first read those examples, and many like them throughout the book,  I kept on thinking

.oO(What’s with those method names. How on Earth does he know what’s going on?)

After some time I realised - whilst reading the code examples I was ignoring the ‘return types’.

PHP doesn’t have return types declared in the method signature and, having never been a Java Developer, my brain just was not trained to pay as much attention to them.

I do not intend to learn Java for a good while yet. So, as a PHP developer, thinking about high level OOP Concepts in PHP  but reading Java examples - I’m, sort of, subconsciously skipping the Java bits out.

Hence, this code:

public DomainObject Find (DataRow row)  {

goes into my brain like:

public BlahBlahJavaStuff Find (DataRow row)  {

or if i’m in a hurry:

public Find (DataRow row)  {

At this point I think .oO(Pah! C’mon that’s hardly a revealing interface is it now!).

A very subtle difference. By simply READING JAVA LIKE A JAVA PROGRAMMER WOULD DO, those code examples make a whole lot more sense.

Its probably so obvious that it does not get mentioned hardly at all. Or I’m just dumb.

Anyway, to translate a method that returns a DomainObject, a PHP developer would write:

public function  FindDomainObject (DataRow row)  {

————

Leave a Reply