Guest User

Untitled

a guest
Jun 2nd, 2014
580
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. You probably know, that in Javascript (and also Ruby) there is no concept of interfaces. There is only a concept of inheritance, but you can't assume that a certain method or property exists, just because it exists in the parent prototype / class. We want to find out, whether a given object fulfils the requirements to implement the "SantaClausable" interface. We need to implement a method which checks for this interface.
  2.  
  3. Rules
  4.  
  5. The SantaClausable interface is implemented, if all of the following methods are defined on an object:
  6. •sayHoHoHo() / say_ho_ho_ho
  7. •distributeGifts() / distribute_gifts
  8. •goDownTheChimney() / go_down_the_chimney
  9.  
  10. Example
  11.  
  12.  
  13. class SantaClaus
  14. def say_ho_ho_ho
  15. # Ho Ho Ho!
  16. end
  17.  
  18. def distribute_gifts
  19. # Gifts for all!
  20. end
  21.  
  22. def go_down_the_chimney
  23. # Whoosh!
  24. end
  25. end
  26.  
  27. class NotSantaClaus
  28. def say_ho_ho_ho
  29. end
  30. end
  31.  
  32. is_santa_clausable(SantaClaus.new) # must return TRUE
  33. is_santa_clausable(NotSantaClaus.new) # must return
Advertisement
Add Comment
Please, Sign In to add comment