Adding a class variable to a package

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding a class variable to a package

Fernando Rodríguez
Hi,

Is it possible to add a class variable to a package? I had to reinstall
dolphin on my new computer and after loading a package, I got errors
complaining about a class variable that wasn't added to that package
but is needed by the loose methods.

If you can't add clas variables to packages, how do you solve this sort
of dependencies?


Reply | Threaded
Open this post in threaded view
|

Re: Adding a class variable to a package

Ian Bartholomew-19
Fernando,

> Is it possible to add a class variable to a package?

Yes it is.  In the package's "PreInstall" script just put ....

YourClass addClassVarName: 'YourClassVarName'

That will be evaluated before the rest of the package is loaded and should
solve the problem.


Whether it is an advisable thing to do is another matter of course :-)

--
Ian

Use the Reply-To address to contact me.
Mail sent to the From address is ignored.


Reply | Threaded
Open this post in threaded view
|

Re: Adding a class variable to a package

Fernando Rodríguez
Ian Bartholomew wrote:

> Fernando,
>
> > Is it possible to add a class variable to a package?
>
> Yes it is.  In the package's "PreInstall" script just put ....
>
> YourClass addClassVarName: 'YourClassVarName'
>
> That will be evaluated before the rest of the package is loaded and should
> solve the problem.
>
>
> Whether it is an advisable thing to do is another matter of course :-)

Why do you think it's a bad idea and how would you solve this sort of
situation? O:-)

Thanks


Reply | Threaded
Open this post in threaded view
|

Re: Adding a class variable to a package

Ian Bartholomew-19
Fernando,

> Why do you think it's a bad idea and how would you solve this sort of
> situation? O:-)

Probably just pure prejudice on my part.  I assume, from the way your
question was phrased, that you want to add the ClassVar to class that is
part of the standard image.   Making any changes to image classes is
something that, over the years, I've found to be best avoided (I suppose it
does depend a bit on which classes you want to modify though).  I can't give
you any specific reason - I can't say "modify a class' variables and _this_
will happen" - it's just something I try to avoid (prejudice :-) ).

You haven't said what "this sort of situation" is?.  However a couple of
things that might help are -

- Using a property rather than a new ClassVar.  As in

YourClass propertyAt: '#whatever put: 'something'
and
YourClass propertyAt: #whatever

Wrap them in accessor methods and it becomes invisible.

- Subclassing the class with one that you own and using that instead

--
Ian

Use the Reply-To address to contact me.
Mail sent to the From address is ignored.