Le mercredi 17 décembre 2008, Nils Meier a écrit :
> Hi Daniel
>
> a static field or method could in theory be used to pass state like that
> from report to report. This is not necessarily always continue to work
> though since reports might be in different classloaders in the future - in
> short: they're not supposed to know of each other or depend on common code.
>
> What shared class is this about? Why wouldn't each report simply create its
> own instance of Alpha()?
Nils the idea here is for example on name partition I have know more than one 
Report like :
- build- update a name partition,
- up-date all name partitions (as the user can in the present situation move 
and indi with the _CLAS tag from one family to another this is very useful),
- get all family name variations in a particular name partition,
- get all individuals that belong to a particular name partition (being under 
construction)

Those different reports located at the same level use common code but further 
more common objects and here the idea is to use for example a common class 
that will build an array ; the first report executed build the instance and 
other reports can use it or update it ; it could be more efficient if 
generating this array may take some time rather than recreating a copy of this 
array with another report in parallel, that is all ; apparently here what I am 
tackling is re-usability with some possible up-date of a particular instance 
between different other instances to optimize running of an application.
Regards.
> Cheers
> Nils
>
> On Wed, Dec 17, 2008 at 7:00 AM, Daniel Moyne <[email protected]> wrote:
> > Nils,
> > when you have many reports taht uses the same class instance how to
> > optimize
> > source layout to get benefit of this for example report one instanciate
> > class
> > "Alpha" :
> > Alpha toto = new Alpha ();
> > then if another report of same style wants to use toto without recreting
> > a new
> > instance that as a maatter of fact would be equivalent to "toto" how to
> > test
> > the existence or not of "toto" in something lioke :
> > if (toto exists) {
> >        /* nothing to be done
> >        * "toto can be used"
> >        */
> > } else {
> >        Alpha toto = new Alpha () ;
> > }
> >
> > I know already how to create a static method in the class Alpha called
> > getInstance() that can be used outside without knowing the instance name
> > to get it and it works ; something like :
> > if (Alpha.getInstance() != null) {
> >        Alpha toto=Alpha.getInstance();
> > } else {
> >        /* we need to create the instance
> >        */
> >        Alpha toto = new Alpha () ;
> > }
> >
> > May be this second method is the most efficient and elegant.
> > Regards.
I put more thought at this having for this particular topics a broder wiew :
I magine Nils the following situation : we still have the Alpha class with its 
static method ;
I do this :
Alpha toto=Alpha.getInstance();
Alpha titi=Alpha.getInstance();

What will happend if I do :
Alphat xxx = Alpha.getInstance();
as now I will have 2 instances built and I recall that my Alpha class has got 
the following static method (code approximative) :

static instance=this;
.....
static getInstance() {
        return (instance);
}
Apparently it has no sense because with static members in a class you are 
supposed to handle either common member values between instances attached to 
the class and method of this class that could be used to get those common 
member values or change them.

Regards.
-- 
Daniel Moyne (Nulix)---------------------------------------------------------
Distribution : Ubuntu 8.04 Hardy Heron    \\|||// Machine : x86_64
               kernel 2.6.24-19-generic   / --- \ ATI Radeon X300 Express
               KDE 3.5.10+4.1.0(test)    (' o-o ')
----------------------------------------oOO-(_)-OOo--------------------------

Attachment: signature.asc
Description: This is a digitally signed message part.

Répondre à