[Gambas-user] 38 different classes - all exactly the same.

Bruce bbruen at ...2308...
Wed Sep 5 11:55:58 CEST 2012


On Tue, 2012-09-04 at 18:21 -0300, Fabián Flores Vadell wrote:
> > What I'd like to be able to do is have only one of these, rather than
> > 38.
> >
> > The reason that the metadata is held as a static attribute is that
> > during any execution of a given program, there might be hundreds
> > (sometimes thousands) of, say, Horse objects created.  So it makes sense
> > to only load the metadata once and share it amongst all the BO's of that
> > type.
> 
> I think you could move the shared behaviour to the Persistor class,
> and use a class collection (defined as static private in Persistor) to
> save the name of each of your current 38 classes, linked to the
> references to the corresponding instances of BOMeta. In this way you
> would have just one reference to a BOMeta object for each key in the
> collection.

That looks to be the solution! Two of us have been looking at this for a
few days and neither came up with that idea.

> (If you find that the prev option isn't good enought, you could create
> just one subclass of Persistor with the mentioned collection.)

Probably not necessary.

> 
> In the next future, if you discover the need to have _p*BO classes
> (i.e. if you found differents behaviours for they) you can add the
> hierarchy of relevant classes.

That's what the original design concept "thought".  But, due to the
general wonderfulness of Gambas, the need has gone away.

> 
> > So, is there some way to create a class i.e. a new class not a new
> > object, based on that common code at runtime?
> 
> I think  is impossible because Gambas isn't reflexive. I tried to hack
> the Gambas features in order to do this, just for fun, but I failed
> miserably :-(
> 
> Anyway, if would be possible to do, you will end with a kludge, and
> you can't warrantee that the ugly hack will work in the next Gambas
> release.

But, thanks to you this is no longer needed!

Now, if there was only a way to create Properties on the fly ... 
Nah!, I'll leave that one up to the Gods. :-)

> 
> Regards.
> Fabián.

Fabián,

Thanks for taking the time to look at this.  It took us all of today to
recast the persistor class but it was well worth it as not only did we
get rid of the specialised persistors but strangely it simplified some
other aspects.

Please find a few (virtual) beers attached ;-)

regards
Bruce

http://upload.wikimedia.org/wikipedia/en/thumb/6/68/Darwin_stubby.jpg/800px-Darwin_stubby.jpg






More information about the User mailing list