PHP OOP: Unique method per argument type?

Posted by sunwukung on Stack Overflow See other posts from Stack Overflow or by sunwukung
Published on 2010-05-07T14:40:04Z Indexed on 2010/05/07 14:48 UTC
Read the original article Hit count: 180

Filed under:
|
|
|

I'm writing a little homebrew ORM (academic interest). I'm trying to adhere to the TDD concept as a training exercise, and as part of that exercise I'm writing documentation for the API as I develop the class.

Case in point - I'm working on a classic "getCollection" type mapper class. I want it to be able to retrieve collections of asset X (let's say blog posts) for a specific user, and also collections based on an arbitrary array of numeric values. So - you might have a method like any one of these

$User = $UserMapper->load(1);
$ArticleCollection = $ArticleMapper->getCollection(range(10,20));
$ArticleCollection = $ArticleMapper->getCollection($User);
$ArticleCollection = $ArticleMapper->getCollection($User->getId());

So, in writing the documentation for the getCollection method - I want to declare the @param variable in the Docblock. Is it better to have a unique method for each argument type, or is it acceptable to have a method that delegates to the correct internal method/class based on argument type?

© Stack Overflow or respective owner

Related posts about oop

Related posts about php