mementos and kind validation on containers

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

mementos and kind validation on containers

Philippe Marschall
Hi

Recently #kind was made mutable on MADescription. I think this is
great and set it on the containers of my model classes to my model
classes. This allows me to do the following:

aDescription kind new

which is really cool. The problem is that now I always get kind
validation errors. The cause is the following code in MADescription:

validateKind: anObject
        "Validate ==anObject== to be of the right kind."

        (anObject isKindOf: self kind)
                ifFalse: [ MAKindError description: self signal: self kindErrorMessage ]

anObject would be an MACheckedMemento. self kind would previously
always answer Object so this test would always pass. Now however self
kind answers my model class and always fails.

Any ideas?

Cheers
Philippe
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: mementos and kind validation on containers

Lukas Renggli
> Any ideas?

I think you should not use #kind to instantiate new objects, but add
your own property to hold the class you want to instantiate.

Cheers,
Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: mementos and kind validation on containers

Philippe Marschall
2009/9/12 Lukas Renggli <[hidden email]>:
>> Any ideas?
>
> I think you should not use #kind to instantiate new objects, but add
> your own property to hold the class you want to instantiate.

That doesn't solve the problem that kind validation is borken for containers.

Cheers
Philippe
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: mementos and kind validation on containers

Lukas Renggli
>> I think you should not use #kind to instantiate new objects, but add
>> your own property to hold the class you want to instantiate.
>
> That doesn't solve the problem that kind validation is borken for containers.

#kind is used for validation and that should remain like this. The
default for containers is Object, so it is a no-op that passes the
validation for all objects.

Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: mementos and kind validation on containers

Philippe Marschall
2009/9/13 Lukas Renggli <[hidden email]>:
>>> I think you should not use #kind to instantiate new objects, but add
>>> your own property to hold the class you want to instantiate.
>>
>> That doesn't solve the problem that kind validation is borken for containers.
>
> #kind is used for validation and that should remain like this. The
> default for containers is Object, so it is a no-op that passes the
> validation for all objects.

Not if you set kind on a container. And the check is not a no-op at
all. It checks the class of the memento against the kind which makes
no sense at all.

Cheers
Philippe
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: mementos and kind validation on containers

Lukas Renggli
2009/9/13 Philippe Marschall <[hidden email]>:

> 2009/9/13 Lukas Renggli <[hidden email]>:
>>>> I think you should not use #kind to instantiate new objects, but add
>>>> your own property to hold the class you want to instantiate.
>>>
>>> That doesn't solve the problem that kind validation is borken for containers.
>>
>> #kind is used for validation and that should remain like this. The
>> default for containers is Object, so it is a no-op that passes the
>> validation for all objects.
>
> Not if you set kind on a container. And the check is not a no-op at
> all. It checks the class of the memento against the kind which makes
> no sense at all.

Of course, for what it is designed for it makes perfectly sense.

As I already said several times, forget about #kind, create your own
property that is not used for validation and do with it whatever you
want.

Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: mementos and kind validation on containers

Philippe Marschall
2009/9/13 Lukas Renggli <[hidden email]>:

> 2009/9/13 Philippe Marschall <[hidden email]>:
>> 2009/9/13 Lukas Renggli <[hidden email]>:
>>>>> I think you should not use #kind to instantiate new objects, but add
>>>>> your own property to hold the class you want to instantiate.
>>>>
>>>> That doesn't solve the problem that kind validation is borken for containers.
>>>
>>> #kind is used for validation and that should remain like this. The
>>> default for containers is Object, so it is a no-op that passes the
>>> validation for all objects.
>>
>> Not if you set kind on a container. And the check is not a no-op at
>> all. It checks the class of the memento against the kind which makes
>> no sense at all.
>
> Of course, for what it is designed for it makes perfectly sense.
>
> As I already said several times, forget about #kind, create your own
> property that is not used for validation and do with it whatever you
> want.

But why is #kind mutable on MADescription when setting it results in
failing validation? This is very bad API design. At least it should be
pushed down to MAElement description.

Cheers
Philippe
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: mementos and kind validation on containers

Lukas Renggli
2009/9/13 Philippe Marschall <[hidden email]>:

> 2009/9/13 Lukas Renggli <[hidden email]>:
>> 2009/9/13 Philippe Marschall <[hidden email]>:
>>> 2009/9/13 Lukas Renggli <[hidden email]>:
>>>>>> I think you should not use #kind to instantiate new objects, but add
>>>>>> your own property to hold the class you want to instantiate.
>>>>>
>>>>> That doesn't solve the problem that kind validation is borken for containers.
>>>>
>>>> #kind is used for validation and that should remain like this. The
>>>> default for containers is Object, so it is a no-op that passes the
>>>> validation for all objects.
>>>
>>> Not if you set kind on a container. And the check is not a no-op at
>>> all. It checks the class of the memento against the kind which makes
>>> no sense at all.
>>
>> Of course, for what it is designed for it makes perfectly sense.
>>
>> As I already said several times, forget about #kind, create your own
>> property that is not used for validation and do with it whatever you
>> want.
>
> But why is #kind mutable on MADescription when setting it results in
> failing validation? This is very bad API design. At least it should be
> pushed down to MAElement description.

Indeed, you are right, but that has nothing to do with the initial problem.

Maybe the MAMemento should rather implement #isKindOf: to dispatch to
the delegate?

Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: mementos and kind validation on containers

Philippe Marschall
2009/9/13 Lukas Renggli <[hidden email]>:

> 2009/9/13 Philippe Marschall <[hidden email]>:
>> 2009/9/13 Lukas Renggli <[hidden email]>:
>>> 2009/9/13 Philippe Marschall <[hidden email]>:
>>>> 2009/9/13 Lukas Renggli <[hidden email]>:
>>>>>>> I think you should not use #kind to instantiate new objects, but add
>>>>>>> your own property to hold the class you want to instantiate.
>>>>>>
>>>>>> That doesn't solve the problem that kind validation is borken for containers.
>>>>>
>>>>> #kind is used for validation and that should remain like this. The
>>>>> default for containers is Object, so it is a no-op that passes the
>>>>> validation for all objects.
>>>>
>>>> Not if you set kind on a container. And the check is not a no-op at
>>>> all. It checks the class of the memento against the kind which makes
>>>> no sense at all.
>>>
>>> Of course, for what it is designed for it makes perfectly sense.
>>>
>>> As I already said several times, forget about #kind, create your own
>>> property that is not used for validation and do with it whatever you
>>> want.
>>
>> But why is #kind mutable on MADescription when setting it results in
>> failing validation? This is very bad API design. At least it should be
>> pushed down to MAElement description.
>
> Indeed, you are right, but that has nothing to do with the initial problem.
>
> Maybe the MAMemento should rather implement #isKindOf: to dispatch to
> the delegate?

I though about this first too. However now I'm affraid of the possible
things it would break (debuggers, inspectors, ...). Considering that
something as simple as implementing #asString in Object can crash
VisualWorks this makes me very nervous. Maybe specifically handling
mementos or #magritteIsKindOf: are better.

Cheers
Philippe
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki