IMO,
FlyWieghts are helpful in reducing the number of instances you create in a
one process.
My example is not best of the examples in practicall scenarios but it will
do for a sample.
e.g SUPPOSE you have a class
Child
{
Parent parent;
String name;
int age;
}
and there is some program who will add the child to the database.Say
addChild(Child c).
So, if you have 3 childrens. what you will do is create 3 child instances.
However, if we CHANGE our programming in a way that we have addChild(Parent
p, String childName, int childAge), we have reduced the number of objects to
be created by 3.
What you are saying about FlyWeight seems to be more closer to the Paging
Pattern, where one needs only the subset of total results obtained.
- Navjot Singh
|-----Original Message-----
|From: An interest list for Sun Java Center J2EE Pattern Catalog
|[mailto:J2EEPATTERNS-INTEREST@(protected)
|Sent: Tuesday, August 21, 2001 11:52 AM
|To: J2EEPATTERNS-INTEREST@(protected)
|Subject: Flyweight vs Value Object
|
|
|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)