On 15 Feb 2017, at 10:56, Ben Coman <btc@openinworld.com> wrote:
On Wed, Feb 15, 2017 at 3:38 PM, Alistair Grant <akgrant0710@gmail.com> wrote: I'm developing a number of classes where it would be convenient to be able to inspect what might be described as calculated attributes, i.e. the result of a unary message send. The result isn't stored in an instance variable, but is still useful when inspecting.
I can obviously develop an inspector extension for my application, but was wondering if there is a framework in place that allows a list of attributes to be declared that can also be inspected in a similar fashion to normal instance variables.
Many thanks to Doru and everyone who has contributed to the GT Inspector framework. It has significantly influenced my development and the architecture of the software I'm currently working on (in a positive way, of course).
Would it be feasible to have a "CalculationSlot" that was read only, and each time it was read it performed the calculation?
Using a âvirtualâ slot would be possible⦠it would look like a instance variable, (you can read from it and the calculation is done). I think it is a bit of overkill (and the machinery is a bit unused, so bugs will be found). Here is how this works: First we define a new kind of Instance Variable (we call them slots): Now enable the setting "Class Template with Slotsâ and you add a class like this: Slot subclass: #VirtualSlot slots: { #block } classVariables: { } category: 'Slot-Examplesâ As you can see, it stores a block which es evaluated on read. So next, we need a setter: with: aBlock block := aBlock and a method that defines what happens of reading from such a strange var: read: anObject ^block value: anObject and as this is read only, write: aValue to: anObject self error: 'read only' and finally, a print method so it is rendered in the class definition view: printOn: aStream aStream store: self name; nextPutAll: ' => '; nextPutAll: self class name; nextPutAll: ' with: '; nextPutAll: block printString Object subclass: #TT slots: { #i => VirtualSlot with: [ :o | o class methods size ] } classVariables: { } category: âTT' add an accessor: i ^i and then you can to âTT new iâ, add a second method and see how the value changes. And you can inspect âTT newâ and you see that the i looks like a normal ivar. Marcus