views:

25

answers:

2

I have an abstract data mapper class:

<?php
abstract class ADataMapper
{
    abstract public function addNew($dataObj);
    abstract public function update($dataObj);
    abstract public function find($primaryKey);
    abstract public function delete($dataObj);
}
?>

In a sub-class of ADataMapper, I need to find a row by a column that is not the primary key, specifically: 'filename'.

Would it be best to implement a method like findByFilename($filename) or is there another, simpler alternative? I feel like I am just adding more complexity than necessary.

+1  A: 

You could add a check within find(). If the argument is a string then call a private findByFileName() otherwise, findById()

Angelo R.
Combine this with Wrikken so that you can pass in an `array('fieldName'=>'searchTerm')` etc. Then you can check if it's an `int` -> `findById()`, otherwise do a search.
Blair McMillan
+1  A: 

Normally I go for getBySpecificKeyX methods (so getById()/getByParentId() kind of family), and a general search() method which takes a construct/array of multiple searchterms and queries dynamically. That is a personal choice though.

Wrikken