[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.programming

Two classes vs two methods in one class?

Victor Porton

10/3/2015 3:20:00 PM

I need an iterator which returns "processed" data (a function applied to the
unprocessed data received from a DB) and an iterator which return both
processed an unprocessed data (as a structure having ->processed and -
>unprocessed fields).

Should I make two classes of iterators (probably with a common ancestor) or
one class of iterators but two methods, one returning processed data and one
returning both processed and unprocessed?

The first scenario:

$iter1 = FirstIteratorClass;
while($iter1->fetch) { # returns processed data only
...
}
$iter2 = SecondIteratorClass;
while($iter2->fetch) { # returns both processed and unprocessed data
...
}

The second scenario:

$iter1 = IteratorClass;
while($iter1->fetch) { # returns processed data only
...
}
$iter2 = IteratorClass;
while($iter2->fetch_all_data) { # returns both processed and unprocessed
data
...
}


--
Victor Porton - http://porton...
1 Answer

Marco Bakera

10/3/2015 7:07:00 PM

0

Victor Porton schrieb am 03.10.2015 um 17:19:
> I need an iterator which returns "processed" data (a function applied to the
> unprocessed data received from a DB) and an iterator which return both
> processed an unprocessed data (as a structure having ->processed and
> -> unprocessed fields).

It seems you are using classes as data containers and not as living
things. That often happens when OR-mapping comes into place. I would
prefer to give some processing method to the entities.

If you want to rely on your decision it should be better to split
functionality into classes (first scenario) - at least if you plan to
implement it in an object-oriented manner.



Best,
Marco.