Guest User

Untitled

a guest
Aug 14th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. Refactoring if-chains in Smalltalk without class explosion
  2. self condition1
  3. ifTrue: [ self actionForCondition1 ]
  4. ifFalse: [
  5. self condition2
  6. ifTrue: [ self actionForCondition2 ]
  7. ifFalse: [
  8. self condition3
  9. ifTrue: [ self actionForCondition3 ]
  10. ifFalse: [ .... ] ] ]
  11.  
  12. anObject isKindOf: aClass
  13.  
  14. anObject = anotherObject
  15.  
  16. self condition1
  17. ifTrue: [ ^ self actionForCondition1 ].
  18. self condition2
  19. ifTrue: [ ^ self actionForCondition2 ].
  20. self condition3
  21. ifTrue: [ ^ self actionForCondition3 ].
  22. ...
  23.  
  24. selector = selector1 ifTrue: [ invoke method1 ]
  25. ifFalse: [ selector= selector2 ifTrue: [ invoke method2 ]
  26. ifFalse: [...] ]]].
Add Comment
Please, Sign In to add comment