Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #5913 > unrolled thread

Two classes vs two methods in one class?

Started byVictor Porton <porton@narod.ru>
First post2015-10-03 18:19 +0300
Last post2015-10-03 21:06 +0200
Articles 2 — 2 participants

Back to article view | Back to comp.programming


Contents

  Two classes vs two methods in one class? Victor Porton <porton@narod.ru> - 2015-10-03 18:19 +0300
    Re: Two classes vs two methods in one class? Marco Bakera <pintman@bakera.de> - 2015-10-03 21:06 +0200

#5913 — Two classes vs two methods in one class?

FromVictor Porton <porton@narod.ru>
Date2015-10-03 18:19 +0300
SubjectTwo classes vs two methods in one class?
Message-ID<muorn0$loh$1@speranza.aioe.org>
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://portonvictor.org

[toc] | [next] | [standalone]


#5914

FromMarco Bakera <pintman@bakera.de>
Date2015-10-03 21:06 +0200
Message-ID<mup8vo$gal$1@news.albasani.net>
In reply to#5913
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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.programming


csiph-web