Return types, or types to return..
Posted: Tue Aug 22, 2006 7:54 am
A bit of an ambiguous title, apologies..
In examples such as d11's fabulous MySQL and Result Iterator class(es) we see an object returning it's value in a predefined type. In that specific case, the DB_Result object.
I've always designed my objects/classes with the intent of as much flexibility as possible, such as can be seen in my PHP5 Paginator - originally set to accept iArrayObjects but later changed to use primitive Arrays, and also it only returns arrays. It was suggested that the data be returned in an iterator..
However, I'm of 'the belief' that if I, or another developer wishes for that data to be an Iterator, they can do it themselves by either creating an Iterator object of their choice, or looping through the returned value.
However - this has now, in my infinite boredom at work, got me thinking.. which is the "better" practice? return a predefined type and assume the data will always be used in an iterator fashion, or return the data as a pritive type (where possible) leaving it open for as many possibilities as .. possible?
Have I got the wrong/right end of the stick with regards to OOP/D?
The reason I ask, is because lets say I was to use d11wtq's class(es) in conjunction with my paginator, I would then have to rework one or the other to be able to plug my paginator on to the result set.
[/random train of thought babble]
[back to learning about project design]
In examples such as d11's fabulous MySQL and Result Iterator class(es) we see an object returning it's value in a predefined type. In that specific case, the DB_Result object.
I've always designed my objects/classes with the intent of as much flexibility as possible, such as can be seen in my PHP5 Paginator - originally set to accept iArrayObjects but later changed to use primitive Arrays, and also it only returns arrays. It was suggested that the data be returned in an iterator..
However, I'm of 'the belief' that if I, or another developer wishes for that data to be an Iterator, they can do it themselves by either creating an Iterator object of their choice, or looping through the returned value.
However - this has now, in my infinite boredom at work, got me thinking.. which is the "better" practice? return a predefined type and assume the data will always be used in an iterator fashion, or return the data as a pritive type (where possible) leaving it open for as many possibilities as .. possible?
Have I got the wrong/right end of the stick with regards to OOP/D?
The reason I ask, is because lets say I was to use d11wtq's class(es) in conjunction with my paginator, I would then have to rework one or the other to be able to plug my paginator on to the result set.
[/random train of thought babble]
[back to learning about project design]