Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Ruby OOP: Objects over Classes


Published on

A talk presented in RubyConf India 2010 at Bangalore, India. It revisits the role of objects and classes in Ruby OOP, and encourages programmers to discover a new approach to OOP.

Published in: Technology
  • The code companion for this talk can be found here:

    The code in comicbook directory was referred to after the comic book cover slide; the code in examples directory was referred to after the 'Finding hints in the real world' slide.
    Are you sure you want to  Yes  No
    Your message goes here

Ruby OOP: Objects over Classes

  1. Ruby OOP: Objects over Classes<br />Aman King<br /><br />RubyConf India 2010<br />
  2. What is OOP?<br />
  3. What is a class?<br />
  4. What is an object?<br />
  5. But before the serious stuff …<br />
  6. Detouring through a comic book universe …<br />Image copyrighted by respective owners<br />Source:<br />
  7. Coming back …<br />
  8. What is an object?<br />
  9. Something that takes birth …<br />
  10. exhibits some behavior …<br />
  11. interacts with other objects …<br />
  12. and finally dies off <br />or <br />is simply forgotten …<br />
  13. all in an effort to solve a problem.<br />
  14. What is a class?<br />
  15. A container for related behavior …<br />
  16. that a new object can start off with.<br />
  17. A class itself is an object …<br />
  18. used to create other objects.<br />
  19. When creating a new object, <br />a class calls the object’s <br />private initialize method.<br />
  20. Typically a class is named …<br />
  21. referenced via <br />a global constant variable.<br />
  22. A class object can have singleton methods added to it.<br />
  23. These singleton methods can be invoked wherever the class object is accessible …<br />
  24. aka <br />“class-level methods”.<br />
  25. Why use classes?<br />
  26. Some possible reasons<br />
  27. An object remembers the class used to create it …<br />
  28. explicit type checking <br />using kind_of? …<br />
  29. implicit type checking <br />using case syntax …<br />
  30. implicit type checking <br />using rescue syntax.<br />
  31. A class can build on other classes: <br />inheritance.<br />
  32. A class can share state <br />across multiple objects: <br />@@class_variables.<br />
  33. Some good reasons<br />
  34. A named container of behavior can have more behavior added to it.<br />
  35. Any added behavior becomes part of all objects created by that class.<br />
  36. A class can represent <br />a common pattern of initialization.<br />
  37. Classes improve <br />readability and maintainability.<br />
  38. What a class is not?<br />
  39. The fundamental building block <br />of an application.<br />
  40. A strong data type.<br />
  41. An enforcement of <br />contract or limitations <br />on how objects can behave.<br />
  42. Ruby’s object focus<br />
  43. Classes are objects.<br />
  44. No static method-lookup tables: <br />chain of ancestors.<br />
  45. Singleton methods.<br />
  46. Private access modifier <br />is object-level.<br />
  47. Duck typing.<br />
  48. Finding hints in the real world …<br />
  49. Objects over classes: Consequences<br />
  50. Classes and hierarchies <br />no longer limit you.<br />
  51. Think through the usage of<br />class-level methods and variables: globals?<br />
  52. Understanding meta-programming is easier.<br />
  53. Effective and confident <br />use of meta-programming.<br />
  54. Final words<br />
  55. Objects are first-class citizens.<br />
  56. Classes are useful but secondary.<br />
  57. Thank you<br /><br /><br />