The code of Pharo for + **may** be rewritten using double dispatch but it is not that clear to me especially the adaptToInteger logic and we do not change for the sake of it :) There are plenty of places we should improve and that are really important. In Pillar, or compiler we have many more nodes and there a Visitor is clearly the way to go. Now you should try and sketch something and let us know. There is not need to create a superclass between die and dieHandle because DD is not based on nominal subtyping. We just need objects proposing the correct API. I use abstract superclass when I want to really push on contract or interfaces. Now in this book I did not want to stress inheritance. So I wanted to have a solution stressing messages because often people forget that messages and polymorphism are powerful and not systematically linked with inheritance. Stef On Tue, Aug 29, 2017 at 6:47 PM, Yves Lenfant <lenfantyv@wanadoo.fr> wrote:
Ooops I wasn't int the mailing list, lets try again
Hello Steph,
I have questions about the concept because,probably, I miss something. I am not sneaky, let me explain.
If we analyse the Kernel Numbers package, and we dissect the relation between Float, Fraction and Integer (Pharo 5.0) for example, the '+' method in the class Integer. We read:
+ aNumber "Refer to the comment in Number + "
aNumber isInteger ifTrue: [ self negative == aNumber negative ifTrue: [ ^ (self digitAdd: aNumber) normalize ] ifFalse: [ ^ self digitSubtract: aNumber ] ]. aNumber isFraction ifTrue: [ ^ Fraction numerator: self * aNumber denominator + aNumber numerator denominator: aNumber denominator ]. ^ aNumber adaptToInteger: self andSend: #+
and we have similar '+'method containing complementary tests in the other class Float and Fraction. And an overall '+' method in the class Number
+ aNumber "Answer the sum of the receiver and aNumber."
self subclassResponsibility
I precise that a long time ago as an academic exercice, I developped a 'Complex' class using this way above (So I add tests).
My questions: You say it's better to use double dispatch, so in this case, can we apply it for the Number subclasses?
It is good or unnecesary to create a super class 'Dicable' containing a '+' method with
+ aNumber "Answer the sum of the receiver and aNumber."
self subclassResponsibility
? is it wasted time or safe code?
Yves
-- View this message in context: http://forum.world.st/new-chapter-on-double-dispatch-for-new-book-tp4963645p... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.