Using Utility classes - follow up to How do I save contents of Workspace into a collection?

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

Using Utility classes - follow up to How do I save contents of Workspace into a collection?

Frank Church
Igor made this comment in relation to this thread.

> indeed.
> I wonder why you (Frank) need such complicated way for doing things.
> If you need a reusable piece of code, which you want to use more than 1 time,
> classes is the best placeholder for them..

> Even if you put things at class side, it helps a lot.. so then you can
> just type:

> MyUtilsClass doThis

> MyUtilsClass doThat

When I was creating the script to automatically add instance variables
and accessors Stack Overflow 14234003,  Mef mentioned that if rather
than run the method against an instance of an object, I could attach
the method to a class, namely ClassDescription.

> You could add it to ClassDescription itself, then you wouldn't even have to pass the class as parameter (because self is the class
> then). You could call ClassX addVariablesNamed: aCollection in this case

Is ClassX an example of the MyUtils class Igor mentions? I tried that
option using ClassDescription but got an MNU error..

e.g. right now I use the first option in this manner:

| anyVariable |
anyVariable := ClassType new.
anyVariable addVarsAndTheirAccessors: #('aaaa' 'bbbb' 'cccc')

How would I attach the method to a utilities class and
ClassDescription for that matter as it would then apply to all
classes?

--
Frank Church

=======================
http://devblog.brahmancreations.com

Reply | Threaded
Open this post in threaded view
|

Re: Using Utility classes - follow up to How do I save contents of Workspace into a collection?

Stéphane Ducasse
Frank

did you see that you can create instance variable accessor using the class browser.
I did not check in OmniBrower in Pharo1.4 but in Nautilus in 2.0 this is there.
And it is a refactoring so it makes sure that you do not override by accident an existing method.

Stef
Reply | Threaded
Open this post in threaded view
|

Re: Using Utility classes - follow up to How do I save contents of Workspace into a collection?

Ben Coman
In reply to this post by Frank Church
Frank Church wrote:

> Igor made this comment in relation to this thread.
>
>  
>> indeed.
>> I wonder why you (Frank) need such complicated way for doing things.
>> If you need a reusable piece of code, which you want to use more than 1 time,
>> classes is the best placeholder for them..
>>    
>
>  
>> Even if you put things at class side, it helps a lot.. so then you can
>> just type:
>>    
>
>  
>> MyUtilsClass doThis
>>    
>
>  
>> MyUtilsClass doThat
>>    
>
> When I was creating the script to automatically add instance variables
> and accessors Stack Overflow 14234003,  Mef mentioned that if rather
> than run the method against an instance of an object, I could attach
> the method to a class, namely ClassDescription.
>
>  
>> You could add it to ClassDescription itself, then you wouldn't even have to pass the class as parameter (because self is the class
>> then). You could call ClassX addVariablesNamed: aCollection in this case
>>    
>
> Is ClassX an example of the MyUtils class Igor mentions? I tried that
> option using ClassDescription but got an MNU error..
>
> e.g. right now I use the first option in this manner:
>
> | anyVariable |
> anyVariable := ClassType new.
> anyVariable addVarsAndTheirAccessors: #('aaaa' 'bbbb' 'cccc')
>
> How would I attach the method to a utilities class and
> ClassDescription for that matter as it would then apply to all
> classes?
>
>  
I don't quite understand you question, but perhaps executing the
following would shed some light...
Morph browseHierarchy
Morph class browseHierarchy

Define the following method...
ClassDescription>>mytest
    self confirm: 'nothing'.

Then execute...
Morph mytest

cheers -ben

Reply | Threaded
Open this post in threaded view
|

Re: Using Utility classes - follow up to How do I save contents of Workspace into a collection?

Ben Coman
Ben Coman wrote:

> Frank Church wrote:
>> Igor made this comment in relation to this thread.
>>
>>  
>>> indeed.
>>> I wonder why you (Frank) need such complicated way for doing things.
>>> If you need a reusable piece of code, which you want to use more
>>> than 1 time,
>>> classes is the best placeholder for them..
>>>    
>>
>>  
>>> Even if you put things at class side, it helps a lot.. so then you can
>>> just type:
>>>    
>>
>>  
>>> MyUtilsClass doThis
>>>    
>>
>>  
>>> MyUtilsClass doThat
>>>    
>>
>> When I was creating the script to automatically add instance variables
>> and accessors Stack Overflow 14234003,  Mef mentioned that if rather
>> than run the method against an instance of an object, I could attach
>> the method to a class, namely ClassDescription.
>>
>>  
>>> You could add it to ClassDescription itself, then you wouldn't even
>>> have to pass the class as parameter (because self is the class
>>> then). You could call ClassX addVariablesNamed: aCollection in this
>>> case
>>>    
>>
>> Is ClassX an example of the MyUtils class Igor mentions? I tried that
>> option using ClassDescription but got an MNU error..
>>
>> e.g. right now I use the first option in this manner:
>>
>> | anyVariable |
>> anyVariable := ClassType new.
>> anyVariable addVarsAndTheirAccessors: #('aaaa' 'bbbb' 'cccc')
>>
>> How would I attach the method to a utilities class and
>> ClassDescription for that matter as it would then apply to all
>> classes?
>>
>>  
> I don't quite understand you question, but perhaps executing the
> following would shed some light...
> Morph browseHierarchy
> Morph class browseHierarchy
>
> Define the following method...
> ClassDescription>>mytest
>    self confirm: 'nothing'.
>
> Then execute...
> Morph mytest
>
> cheers -ben
>
>
btw, do you know that the class definition that you typically see in the
browser is just a message being sent to the superclass ?
For example, in a Workspace or any method you can execute the following....
------
ivars := 'aaa bbb ccc'.
newclass := #MyTest.
Object subclass: newclass
    instanceVariableNames: ivars
    classVariableNames: ''
    poolDictionaries: ''
    category: 'my-playground'
------