aspose file tools*
The moose likes Java in General and the fly likes MVC techniques Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "MVC techniques" Watch "MVC techniques" New topic
Author

MVC techniques

David Pantale
Ranch Hand

Joined: Mar 16, 2010
Posts: 32
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

Joined: Apr 16, 2008
Posts: 2187
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

Joined: Oct 27, 2005
Posts: 19723
    
  20

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
 
subject: MVC techniques