The Inbox: Kernel-cmm.761.mcz

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

The Inbox: Kernel-cmm.761.mcz

commits-2
A new version of Kernel was added to project The Inbox:
http://source.squeak.org/inbox/Kernel-cmm.761.mcz

==================== Summary ====================

Name: Kernel-cmm.761
Author: cmm
Time: 4 July 2013, 9:01:30.236 pm
UUID: b9aaab83-9dfc-4c4f-a4e6-203167954cc1
Ancestors: Kernel-cmm.760

- Introduce AttributableObject, an abstract class whose subclass instances allow a variable number of attributes to be set and accessed at run time.

=============== Diff against Kernel-cmm.760 ===============

Item was added:
+ Object subclass: #AttributableObject
+ instanceVariableNames: 'attributes'
+ classVariableNames: ''
+ poolDictionaries: ''
+ category: 'Kernel-Models'!
+
+ !AttributableObject commentStamp: 'cmm 10/7/2009 21:03' prior: 0!
+ Subclass from this abstract class to inherit an attribute Dictionary.!

Item was added:
+ ----- Method: AttributableObject>>attributeNamed: (in category 'attributes') -----
+ attributeNamed: aString
+ ^ attributes ifNotNil:
+ [ attributes
+ at: aString
+ ifAbsent: [ nil ] ]!

Item was added:
+ ----- Method: AttributableObject>>attributeNamed:put: (in category 'attributes') -----
+ attributeNamed: aString put: anObject
+ anObject ifNotNil: [ attributes ifNil: [ attributes := Dictionary new ] ].
+ ^ anObject
+ ifNil:
+ [ self removeAttributeNamed: aString.
+ anObject ]
+ ifNotNil:
+ [ attributes
+ at: aString
+ put: anObject ]!

Item was added:
+ ----- Method: AttributableObject>>attributesToDeepCopy (in category 'copying') -----
+ attributesToDeepCopy
+ "Subclasses override."
+ ^ attributes
+ ifNil: [ Array empty ]
+ ifNotNil: [ attributes keys ]!

Item was added:
+ ----- Method: AttributableObject>>removeAttributeNamed: (in category 'attributes') -----
+ removeAttributeNamed: aString
+ ^ attributes ifNotNil:
+ [ | answer |
+ answer := attributes
+ removeKey: aString
+ ifAbsent: [ nil ].
+ attributes ifEmpty: [ attributes := nil ].
+ answer ]!

Item was added:
+ ----- Method: AttributableObject>>veryDeepInner: (in category 'copying') -----
+ veryDeepInner: aDeepCopier
+ super veryDeepInner: aDeepCopier.
+ attributes := attributes copy.
+ self attributesToDeepCopy do:
+ [ : eachAttribute | attributes
+ at: eachAttribute
+ ifPresent:
+ [ : value | attributes
+ at: eachAttribute
+ put: (value veryDeepCopyWith: aDeepCopier) ]
+ ifAbsent: [ self error: eachAttribute, ' is not an attribute.' ] ]!


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Kernel-cmm.761.mcz

Tobias Pape
Can’t we name that ‘properties’?
I think that ‘attributes’ is too close to the notion of
attributes in general OO design as well as UML.
These attributes would correspond to our attributes.

Magritte and SqueakSource both provide such properties-bearing
approach; the implementation is similar but does not
(yet) provide the deepcopy stuff; the protocol would be similar
but with ‘at’ instead of ‘named’

Fun fact. Magritte supports descriptions that can access either
 instance variables directly or via accessor, or alternatively,
such a properties dictionary, as long as it is named ‘properties’.


Best
     -Tobias

Am 05.07.2013 um 07:02 schrieb [hidden email]:

> A new version of Kernel was added to project The Inbox:
> http://source.squeak.org/inbox/Kernel-cmm.761.mcz
>
> ==================== Summary ====================
>
> Name: Kernel-cmm.761
> Author: cmm
> Time: 4 July 2013, 9:01:30.236 pm
> UUID: b9aaab83-9dfc-4c4f-a4e6-203167954cc1
> Ancestors: Kernel-cmm.760
>
> - Introduce AttributableObject, an abstract class whose subclass instances allow a variable number of attributes to be set and accessed at run time.
>
> =============== Diff against Kernel-cmm.760 ===============
>
> Item was added:
> + Object subclass: #AttributableObject
> +    instanceVariableNames: 'attributes'
> +    classVariableNames: ''
> +    poolDictionaries: ''
> +    category: 'Kernel-Models'!
> +
> + !AttributableObject commentStamp: 'cmm 10/7/2009 21:03' prior: 0!
> + Subclass from this abstract class to inherit an attribute Dictionary.!
>
> Item was added:
> + ----- Method: AttributableObject>>attributeNamed: (in category 'attributes') -----
> + attributeNamed: aString
> +    ^ attributes ifNotNil:
> +        [ attributes
> +            at: aString
> +            ifAbsent: [ nil ] ]!
>
> Item was added:
> + ----- Method: AttributableObject>>attributeNamed:put: (in category 'attributes') -----
> + attributeNamed: aString put: anObject
> +    anObject ifNotNil: [ attributes ifNil: [ attributes := Dictionary new ] ].
> +    ^ anObject
> +        ifNil:
> +            [ self removeAttributeNamed: aString.
> +            anObject ]
> +        ifNotNil:
> +            [ attributes
> +                at: aString
> +                put: anObject ]!
>
> Item was added:
> + ----- Method: AttributableObject>>attributesToDeepCopy (in category 'copying') -----
> + attributesToDeepCopy
> +    "Subclasses override."
> +    ^ attributes
> +        ifNil: [ Array empty ]
> +        ifNotNil: [ attributes keys ]!
>
> Item was added:
> + ----- Method: AttributableObject>>removeAttributeNamed: (in category 'attributes') -----
> + removeAttributeNamed: aString
> +    ^ attributes ifNotNil:
> +        [ | answer |
> +        answer := attributes
> +            removeKey: aString
> +            ifAbsent: [ nil ].
> +        attributes ifEmpty: [ attributes := nil ].
> +        answer ]!
>
> Item was added:
> + ----- Method: AttributableObject>>veryDeepInner: (in category 'copying') -----
> + veryDeepInner: aDeepCopier
> +    super veryDeepInner: aDeepCopier.
> +    attributes := attributes copy.
> +    self attributesToDeepCopy do:
> +        [ : eachAttribute | attributes
> +            at: eachAttribute
> +            ifPresent:
> +                [ : value | attributes
> +                    at: eachAttribute
> +                    put: (value veryDeepCopyWith: aDeepCopier) ]
> +            ifAbsent: [ self error: eachAttribute, ' is not an attribute.' ] ]!
>
>

Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Kernel-cmm.761.mcz

Tobias Pape


Am 05.07.2013 um 07:13 schrieb Tobias Pape <[hidden email]>:

> Can’t we name that ‘properties’?
> I think that ‘attributes’ is too close to the notion of
> attributes in general OO design as well as UML.
> These attributes would correspond to our attributes.
>
> Magritte and SqueakSource both provide such properties-bearing
> approach; the implementation is similar but does not
> (yet) provide the deepcopy stuff; the protocol would be similar
> but with ‘at’ instead of ‘named’
>
> Fun fact. Magritte supports descriptions that can access either
> instance variables directly or via accessor, or alternatively,
> such a properties dictionary, as long as it is named ‘properties’.
>
>
> Best
>     -Tobias

PS: most likely, the keys into the dict will be Symbols
(just as you use them), so we should use an IdentityDictionary.

>
> Am 05.07.2013 um 07:02 schrieb [hidden email]:
>
>> A new version of Kernel was added to project The Inbox:
>> http://source.squeak.org/inbox/Kernel-cmm.761.mcz
>>
>> ==================== Summary ====================
>>
>> Name: Kernel-cmm.761
>> Author: cmm
>> Time: 4 July 2013, 9:01:30.236 pm
>> UUID: b9aaab83-9dfc-4c4f-a4e6-203167954cc1
>> Ancestors: Kernel-cmm.760
>>
>> - Introduce AttributableObject, an abstract class whose subclass instances allow a variable number of attributes to be set and accessed at run time.
>>
>> =============== Diff against Kernel-cmm.760 ===============
>>
>> Item was added:
>> + Object subclass: #AttributableObject
>> +    instanceVariableNames: 'attributes'
>> +    classVariableNames: ''
>> +    poolDictionaries: ''
>> +    category: 'Kernel-Models'!
>> +
>> + !AttributableObject commentStamp: 'cmm 10/7/2009 21:03' prior: 0!
>> + Subclass from this abstract class to inherit an attribute Dictionary.!
>>
>> Item was added:
>> + ----- Method: AttributableObject>>attributeNamed: (in category 'attributes') -----
>> + attributeNamed: aString
>> +    ^ attributes ifNotNil:
>> +        [ attributes
>> +            at: aString
>> +            ifAbsent: [ nil ] ]!
>>
>> Item was added:
>> + ----- Method: AttributableObject>>attributeNamed:put: (in category 'attributes') -----
>> + attributeNamed: aString put: anObject
>> +    anObject ifNotNil: [ attributes ifNil: [ attributes := Dictionary new ] ].
>> +    ^ anObject
>> +        ifNil:
>> +            [ self removeAttributeNamed: aString.
>> +            anObject ]
>> +        ifNotNil:
>> +            [ attributes
>> +                at: aString
>> +                put: anObject ]!
>>
>> Item was added:
>> + ----- Method: AttributableObject>>attributesToDeepCopy (in category 'copying') -----
>> + attributesToDeepCopy
>> +    "Subclasses override."
>> +    ^ attributes
>> +        ifNil: [ Array empty ]
>> +        ifNotNil: [ attributes keys ]!
>>
>> Item was added:
>> + ----- Method: AttributableObject>>removeAttributeNamed: (in category 'attributes') -----
>> + removeAttributeNamed: aString
>> +    ^ attributes ifNotNil:
>> +        [ | answer |
>> +        answer := attributes
>> +            removeKey: aString
>> +            ifAbsent: [ nil ].
>> +        attributes ifEmpty: [ attributes := nil ].
>> +        answer ]!
>>
>> Item was added:
>> + ----- Method: AttributableObject>>veryDeepInner: (in category 'copying') -----
>> + veryDeepInner: aDeepCopier
>> +    super veryDeepInner: aDeepCopier.
>> +    attributes := attributes copy.
>> +    self attributesToDeepCopy do:
>> +        [ : eachAttribute | attributes
>> +            at: eachAttribute
>> +            ifPresent:
>> +                [ : value | attributes
>> +                    at: eachAttribute
>> +                    put: (value veryDeepCopyWith: aDeepCopier) ]
>> +            ifAbsent: [ self error: eachAttribute, ' is not an attribute.' ] ]!
>>
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Kernel-cmm.761.mcz

Hannes Hirzel
In reply to this post by Tobias Pape
On 7/5/13, Tobias Pape <[hidden email]> wrote:
> Can’t we name that ‘properties’?

+1

> I think that ‘attributes’ is too close to the notion of
> attributes in general OO design as well as UML.
> These attributes would correspond to our attributes.
>
> Magritte and SqueakSource both provide such properties-bearing
> approach; the implementation is similar but does not
> (yet) provide the deepcopy stuff; the protocol would be similar
> but with ‘at’ instead of ‘named’
>
> Fun fact. Magritte supports descriptions that can access either
>  instance variables directly or via accessor, or alternatively,
> such a properties dictionary, as long as it is named ‘properties’.
>
>
> Best
>      -Tobias
>
> Am 05.07.2013 um 07:02 schrieb [hidden email]:
>
>> A new version of Kernel was added to project The Inbox:
>> http://source.squeak.org/inbox/Kernel-cmm.761.mcz
>>
>> ==================== Summary ====================
>>
>> Name: Kernel-cmm.761
>> Author: cmm
>> Time: 4 July 2013, 9:01:30.236 pm
>> UUID: b9aaab83-9dfc-4c4f-a4e6-203167954cc1
>> Ancestors: Kernel-cmm.760
>>
>> - Introduce AttributableObject, an abstract class whose subclass instances
>> allow a variable number of attributes to be set and accessed at run time.
>>
>> =============== Diff against Kernel-cmm.760 ===============
>>
>> Item was added:
>> + Object subclass: #AttributableObject
>> +    instanceVariableNames: 'attributes'
>> +    classVariableNames: ''
>> +    poolDictionaries: ''
>> +    category: 'Kernel-Models'!
>> +
>> + !AttributableObject commentStamp: 'cmm 10/7/2009 21:03' prior: 0!
>> + Subclass from this abstract class to inherit an attribute Dictionary.!
>>
>> Item was added:
>> + ----- Method: AttributableObject>>attributeNamed: (in category
>> 'attributes') -----
>> + attributeNamed: aString
>> +    ^ attributes ifNotNil:
>> +        [ attributes
>> +            at: aString
>> +            ifAbsent: [ nil ] ]!
>>
>> Item was added:
>> + ----- Method: AttributableObject>>attributeNamed:put: (in category
>> 'attributes') -----
>> + attributeNamed: aString put: anObject
>> +    anObject ifNotNil: [ attributes ifNil: [ attributes := Dictionary new
>> ] ].
>> +    ^ anObject
>> +        ifNil:
>> +            [ self removeAttributeNamed: aString.
>> +            anObject ]
>> +        ifNotNil:
>> +            [ attributes
>> +                at: aString
>> +                put: anObject ]!
>>
>> Item was added:
>> + ----- Method: AttributableObject>>attributesToDeepCopy (in category
>> 'copying') -----
>> + attributesToDeepCopy
>> +    "Subclasses override."
>> +    ^ attributes
>> +        ifNil: [ Array empty ]
>> +        ifNotNil: [ attributes keys ]!
>>
>> Item was added:
>> + ----- Method: AttributableObject>>removeAttributeNamed: (in category
>> 'attributes') -----
>> + removeAttributeNamed: aString
>> +    ^ attributes ifNotNil:
>> +        [ | answer |
>> +        answer := attributes
>> +            removeKey: aString
>> +            ifAbsent: [ nil ].
>> +        attributes ifEmpty: [ attributes := nil ].
>> +        answer ]!
>>
>> Item was added:
>> + ----- Method: AttributableObject>>veryDeepInner: (in category 'copying')
>> -----
>> + veryDeepInner: aDeepCopier
>> +    super veryDeepInner: aDeepCopier.
>> +    attributes := attributes copy.
>> +    self attributesToDeepCopy do:
>> +        [ : eachAttribute | attributes
>> +            at: eachAttribute
>> +            ifPresent:
>> +                [ : value | attributes
>> +                    at: eachAttribute
>> +                    put: (value veryDeepCopyWith: aDeepCopier) ]
>> +            ifAbsent: [ self error: eachAttribute, ' is not an
>> attribute.' ] ]!
>>
>>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Kernel-cmm.761.mcz

Chris Muller-3
In reply to this post by Tobias Pape
I already have a lot of code that uses this as it is, referring to
attributeNamed:, etc.  The class is named "AttributableObject" so it
makes sense for the API nomenclature to talk about "attributes" rather
than "properties".  They are supposed to be thought of as attributes
as much as inst-vars, which is why the deepCopy support is there.

Finally, I want to avoid any intersection with Morphics properties
API, and have just a minimal reusable API for attributes that can be
easily separately identifiable from Morph's.


On Fri, Jul 5, 2013 at 12:13 AM, Tobias Pape <[hidden email]> wrote:

> Can’t we name that ‘properties’?
> I think that ‘attributes’ is too close to the notion of
> attributes in general OO design as well as UML.
> These attributes would correspond to our attributes.
>
> Magritte and SqueakSource both provide such properties-bearing
> approach; the implementation is similar but does not
> (yet) provide the deepcopy stuff; the protocol would be similar
> but with ‘at’ instead of ‘named’
>
> Fun fact. Magritte supports descriptions that can access either
>  instance variables directly or via accessor, or alternatively,
> such a properties dictionary, as long as it is named ‘properties’.
>
>
> Best
>      -Tobias
>
> Am 05.07.2013 um 07:02 schrieb [hidden email]:
>
>> A new version of Kernel was added to project The Inbox:
>> http://source.squeak.org/inbox/Kernel-cmm.761.mcz
>>
>> ==================== Summary ====================
>>
>> Name: Kernel-cmm.761
>> Author: cmm
>> Time: 4 July 2013, 9:01:30.236 pm
>> UUID: b9aaab83-9dfc-4c4f-a4e6-203167954cc1
>> Ancestors: Kernel-cmm.760
>>
>> - Introduce AttributableObject, an abstract class whose subclass instances allow a variable number of attributes to be set and accessed at run time.
>>
>> =============== Diff against Kernel-cmm.760 ===============
>>
>> Item was added:
>> + Object subclass: #AttributableObject
>> +    instanceVariableNames: 'attributes'
>> +    classVariableNames: ''
>> +    poolDictionaries: ''
>> +    category: 'Kernel-Models'!
>> +
>> + !AttributableObject commentStamp: 'cmm 10/7/2009 21:03' prior: 0!
>> + Subclass from this abstract class to inherit an attribute Dictionary.!
>>
>> Item was added:
>> + ----- Method: AttributableObject>>attributeNamed: (in category 'attributes') -----
>> + attributeNamed: aString
>> +    ^ attributes ifNotNil:
>> +        [ attributes
>> +            at: aString
>> +            ifAbsent: [ nil ] ]!
>>
>> Item was added:
>> + ----- Method: AttributableObject>>attributeNamed:put: (in category 'attributes') -----
>> + attributeNamed: aString put: anObject
>> +    anObject ifNotNil: [ attributes ifNil: [ attributes := Dictionary new ] ].
>> +    ^ anObject
>> +        ifNil:
>> +            [ self removeAttributeNamed: aString.
>> +            anObject ]
>> +        ifNotNil:
>> +            [ attributes
>> +                at: aString
>> +                put: anObject ]!
>>
>> Item was added:
>> + ----- Method: AttributableObject>>attributesToDeepCopy (in category 'copying') -----
>> + attributesToDeepCopy
>> +    "Subclasses override."
>> +    ^ attributes
>> +        ifNil: [ Array empty ]
>> +        ifNotNil: [ attributes keys ]!
>>
>> Item was added:
>> + ----- Method: AttributableObject>>removeAttributeNamed: (in category 'attributes') -----
>> + removeAttributeNamed: aString
>> +    ^ attributes ifNotNil:
>> +        [ | answer |
>> +        answer := attributes
>> +            removeKey: aString
>> +            ifAbsent: [ nil ].
>> +        attributes ifEmpty: [ attributes := nil ].
>> +        answer ]!
>>
>> Item was added:
>> + ----- Method: AttributableObject>>veryDeepInner: (in category 'copying') -----
>> + veryDeepInner: aDeepCopier
>> +    super veryDeepInner: aDeepCopier.
>> +    attributes := attributes copy.
>> +    self attributesToDeepCopy do:
>> +        [ : eachAttribute | attributes
>> +            at: eachAttribute
>> +            ifPresent:
>> +                [ : value | attributes
>> +                    at: eachAttribute
>> +                    put: (value veryDeepCopyWith: aDeepCopier) ]
>> +            ifAbsent: [ self error: eachAttribute, ' is not an attribute.' ] ]!
>>
>>
>