[Prev][Next][Index][Thread]

Re: Representing percentage




"Scott McKay" <swm@mediaone.net> wrote in message
hrWc6.21786$t3.4383959@typhoon.ne.mediaone.net">news:hrWc6.21786$t3.4383959@typhoon.ne.mediaone.net...
> So -- even in a language like Cecil which supports this kind
> of thing -- you want to either represent percentages as real,
> live classes, or you should just interpret an integer properly
> in the right place.  Note that there's no possibility that you
> will have more than 100 different percentages, right?  If
> you make <percentage> be immutable (the setter for p
> being #f), you can add a 'make' method that chooses from
> 1 of the 101 possible percentage objects, and then share
> among them.  (I think the design pattern weenies would
> say they are using a flyweight coupled with some sort of
> instance factory...)  This is a more portable solution than
> the admittedly cool Gwydion hack.

I like Neel's trick (thanks Neel) but it's important for me to keep the code
portable. I was toying with the instance factory option that you suggested
and bumped into another question - I thought of adding a class-allocated
slot to the <percentage> to hold all instances of <percentage>, and override
make() to either return an instance from that slot or create a new one,
but - how can I access a class-allocated slot if I don't have a reference to
any of its instances (e.g. from the make() override)? I could use a module
variable instead of the class-allocated slot but it won't be the same.





Follow-Ups: References: