It simply isn't the pattern described by the GoF. The intent of the
Flyweight design pattern is to "use sharing to support large numbers of
fine-grained objects efficiently."
An example of it is the design of Swing's JTable. It uses a model, which
provides information about the cells of the table, but doesn't hold any
rendering data. When rendering time, one CellRenderer object is
configured with one cell's data and context (position, selection, etc) a
time, and is responsible for rendering it properly. This way, the table
model doesn't have to hold rendering information (position, color,
border, etc), only its contents.
For handling large sets of data tuples, there is a pattern in "J2EE Core
Patterns", called ValueListHandler. Its 1st Edition is published at
Sun's site:
http://java.sun.com/blueprints/corej2eepatterns/Patterns/index.html
and its 2nd Edition has been released recently (my copy will arrive
soon), with updated and new patterns.
regards
Tetsuo
Sanjiv Kapila wrote:
> Can any one highlight me pros & cons of Flyweight vs Value Object paatern.
> As per my understanding Flyweight calls for dividing the result or their
> transfer across n/w in smaller bunched to avoid overloading whereas value
> object clubs diff. request in one to save multiple calls over network.
>
> Also I would like to know code snippet for making a flyweight pattern i.e.
> segregating a resulset in multiple bunches. I know we have fetchSize() that
> can define the no of records to fetch but how to indicate that pointer for
> starting record. Also what will happen if during this fetching some new
> records are inserted in the requested table?
>
> Regards
> Sanjiv
>
> ====================================================================
> Companion Site: http://www.corej2eepatterns.com
> J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns
> List Archive: http://archives.java.sun.com/archives/j2eepatterns-interest.html
> Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to listserv@(protected)
>
>
====================================================================
Companion Site: http://www.corej2eepatterns.com
J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns
List Archive: http://archives.java.sun.com/archives/j2eepatterns-interest.html
Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to listserv@(protected)