Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MVC techniques

 
David Pantale
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I've noticed a possible issue in Java. With Model View Controller pattern the model keeps the data and it is displayed in the view. However, this seems to mean you may have the same data in two places in the application simultaneously thereby wasting memory. Usually it probably not a big deal but if there is a massive amount of data in JTable or JList it could cut performance . In C++ you can use pointers to help get around some of this issue but what do you do in Java? Does anyone know of any techniques to lessen this or am I just imagining a problem that's not there?

Thanks
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Model-View-Controller design pattern does not specify how it can be implemented, and it can be implemented in many, many different ways. In enterprise-level implementations, data is typically stored in a relational database. When data is in the Model component (in object form) during execution of business logic, it is only there temporarily, e.g. < 1 second.

When data is in the View component (in object form), it also is there for only a short time in the form of Presentation-tier data objects.

Placing massive amounts of data objects in View components may degrade performance and is a questionable design. Humans can only view a small amount of data at any point in time anyway.

Most enterprise-level MVC implementations are running on multiple machines with different memory spaces anyway.
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Pantale wrote:However, this seems to mean you may have the same data in two places in the application simultaneously thereby wasting memory.

On the contrary. The two views share a reference to the same model, which is in memory only once.

In C++ you can use pointers to help get around some of this issue but what do you do in Java?

Java uses references. These act a bit like C/C++ pointers, in that they allow you to refer to the same objects from multiple places. Java variables are never objects themselves; they are references to the actual objects on the heap instead. Just like in C++, except without the dangers of pointer arithmetic.

Does anyone know of any techniques to lessen this or am I just imagining a problem that's not there?

You are indeed
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic