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-tp4963645p4965495.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.

Reply via email to