Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A funny case.

 
Anton Golovin
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am caching the data file in a HashMap in the implementation of the Data class. So, basically, in LOCAL mode, this means that my data model (RoomTableModel extends AbstractDataModel) gets not its own set of objects but references to the cached objects. I have to copy the objects so that my RoomTableModel gets its own separate copy of each record it is passed. Maybe someone would kindly comment if this solution is a good one. It seems to be the only one when caching and local mode, and I am far too much into the project to back out of caching (it also offers great search performance.) Do you think this copying would negatively affect my grade?

Thanks!
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anton,

I think that passing *copies* of the cached records to the presentation layer totally makes sense. So you're OK IMO, but it's only my opinion of course.

Regards,

Phil.
 
mike acre
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A very admirable design goal is to make as many classes immutable as possible. This is especially true of transfer objects. If this is achieved there is no need to make copies.
 
Anton Golovin
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by mike acre:
A very admirable design goal is to make as many classes immutable as possible. This is especially true of transfer objects. If this is achieved there is no need to make copies.


Ah, but my design has 19 classes. I have no transfer objects and use a Map to move data. I think they are looking not for design here but for documented problem-solving, and my project has a few things where problems were solved. It's a thin client, so there is some stuff that needed solving.
[ September 24, 2004: Message edited by: Anton Golovin ]
 
Andy Zhu
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, Anton:

I got confused about your post. I have an adapter to my data class. I guess, no matter the client is local or remote. I am implementing a thin client, so that business logic is at adapter (I used cache too). but in half way of coding client. But so far I don't need to have another copy of the cache, not even in the adapter. In adapter, I don't give the choice of transfer whole cache to the client.

From the point of space efficiency, make a client copy is not a good practice, you waste half of your memory your program used (we are talking the local mode, so the client and server sit on the same machine).
 
Anton Golovin
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Andy Zhu:
Hey, Anton:

I got confused about your post. I have an adapter to my data class. I guess, no matter the client is local or remote. I am implementing a thin client, so that business logic is at adapter (I used cache too). but in half way of coding client. But so far I don't need to have another copy of the cache, not even in the adapter. In adapter, I don't give the choice of transfer whole cache to the client.

From the point of space efficiency, make a client copy is not a good practice, you waste half of your memory your program used (we are talking the local mode, so the client and server sit on the same machine).


Wait till you write the client GUI and implement your own TableModel. Then, you will be forced to copy the values.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic