Object design question

  • Thread starter Thread starter larzeb
  • Start date Start date
L

larzeb

One of my classes generates an array of a custom objects. That array
is passed to a validation class, which sets each member of the array's
isValid property to true or false.

The array is then passed to two more classes for further processing in
a read-only manner.

As I see it, I can pass the array to each of the two classes and let
each of them inspect the isValid property, processing only those those
objects which are true.

Or, after the array is validated, I could create an arraylist and
populate it with only those objects which have the isValid property
set to true, passing the arraylist to the remaining two processes.

Any ideas on which approach might be better? I'm not clear about
encapsulation versus the increased execution time.

TIA
 
Hi larzeb,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to know whether to process on
the original object array or populate another array. If there is any
misunderstanding, please feel free to let me know.

I think you can pass the object array reference to the rest two methods and
process on them directly. I think recreating an array of valid object
really takes time. Also I don't think it will be better than processing on
the original array.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
larzeb said:
One of my classes generates an array of a custom objects. That array
is passed to a validation class, which sets each member of the array's
isValid property to true or false.

The array is then passed to two more classes for further processing in
a read-only manner.

As I see it, I can pass the array to each of the two classes and let
each of them inspect the isValid property, processing only those those
objects which are true.

Or, after the array is validated, I could create an arraylist and
populate it with only those objects which have the isValid property
set to true, passing the arraylist to the remaining two processes.

Any ideas on which approach might be better? I'm not clear about
encapsulation versus the increased execution time.

TIA

Without knowing more of your specific implementation, I would (at first
glance) recommended sticking with the arrays rather than creating
ArrayLists. You risk application performance because of (potential)
boxing/unboxing operations being performed on your custom objects in the
ArrayList.

Chris
 
Thanks for Chris's response.

Hi larzeb,

This is correct, since object arrays are "strong typed", which is more
efficient. While arraylist treat all the contents as objects.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top