SlideShare une entreprise Scribd logo
1  sur  57
Ruby OOP: Objects over Classes

             Aman King
       king@thoughtworks.com

          RubyConf India 2010
What is OOP?
What is a class?
What is an object?
But before the serious stuff …
Detouring through a comic book universe …




           Image copyrighted by respective owners
               Source: http://www.comics.org/
Coming back …
What is an object?
Something that takes birth …
exhibits some behavior …
interacts with other objects …
and finally dies off
          or
is simply forgotten …
all in an effort to solve a problem.
What is a class?
A container for related behavior …
that a new object can start off with.
A class itself is an object …
used to create other objects.
When creating a new object,
 a class calls the object’s
 private initialize method.
Typically a class is named …
referenced via
a global constant variable.
A class object can have singleton
      methods added to it.
These singleton methods can be
invoked wherever the class object
         is accessible …
aka
“class-level methods”.
Why use classes?
Some possible reasons
An object remembers the class
     used to create it …
explicit type checking
  using kind_of? …
implicit type checking
using case syntax …
implicit type checking
 using rescue syntax.
A class can build on other classes:
           inheritance.
A class can share state
across multiple objects:
 @@class_variables.
Some good reasons
A named container of behavior can
 have more behavior added to it.
Any added behavior becomes part
of all objects created by that class.
A class can represent
a common pattern of initialization.
Classes improve
readability and maintainability.
What a class is not?
The fundamental building block
       of an application.
A strong data type.
An enforcement of
   contract or limitations
on how objects can behave.
Ruby’s object focus
Classes are objects.
No static method-lookup tables:
      chain of ancestors.
Singleton methods.
Private access modifier
     is object-level.
Duck typing.
Finding hints in the real world …
Objects over classes:
   Consequences
Classes and hierarchies
  no longer limit you.
Think through the usage of
class-level methods and variables:
             globals?
Understanding meta-programming
           is easier.
Effective and confident
use of meta-programming.
Final words
Objects are first-class citizens.
Classes are useful but secondary.
Thank you

       king@thoughtworks.com
http://www.wikyblog.com/AmanKing

Contenu connexe

Tendances (20)

[OOP - Lec 07] Access Specifiers
[OOP - Lec 07] Access Specifiers[OOP - Lec 07] Access Specifiers
[OOP - Lec 07] Access Specifiers
 
Class as the basis of all computation
Class as the basis of all computationClass as the basis of all computation
Class as the basis of all computation
 
Java- Nested Classes
Java- Nested ClassesJava- Nested Classes
Java- Nested Classes
 
Beauty of metaprogramming
Beauty of metaprogrammingBeauty of metaprogramming
Beauty of metaprogramming
 
Ruby OOP: Objects over Classes
Ruby OOP: Objects over ClassesRuby OOP: Objects over Classes
Ruby OOP: Objects over Classes
 
04 inheritance
04 inheritance04 inheritance
04 inheritance
 
object oriented programming using c++
 object oriented programming using c++ object oriented programming using c++
object oriented programming using c++
 
Reflection and Introspection
Reflection and IntrospectionReflection and Introspection
Reflection and Introspection
 
Paca oops slid
Paca oops slidPaca oops slid
Paca oops slid
 
Pierre Livet: Ontologies, from entities to operations.
Pierre Livet: Ontologies, from entities to operations. Pierre Livet: Ontologies, from entities to operations.
Pierre Livet: Ontologies, from entities to operations.
 
15reflection in c#
15reflection  in c#15reflection  in c#
15reflection in c#
 
java - oop's in depth journey
java - oop's in depth journeyjava - oop's in depth journey
java - oop's in depth journey
 
Inner Classes in Java
Inner Classes in JavaInner Classes in Java
Inner Classes in Java
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Chap02
Chap02Chap02
Chap02
 
Stoop metaclasses
Stoop metaclassesStoop metaclasses
Stoop metaclasses
 
Assigment 2
Assigment 2Assigment 2
Assigment 2
 
Class and object 1
Class and object 1Class and object 1
Class and object 1
 
Class
ClassClass
Class
 
Java Inner Classes
Java Inner ClassesJava Inner Classes
Java Inner Classes
 

En vedette

20130629 If you build it, will they visit [ala lita lightning talk]
20130629 If you build it, will they visit [ala lita lightning talk]20130629 If you build it, will they visit [ala lita lightning talk]
20130629 If you build it, will they visit [ala lita lightning talk]Frederick Zarndt
 
Erlang On Xen @ Kiev Functional Programming event, Aug 3 2013
Erlang On Xen @ Kiev Functional Programming event, Aug 3 2013Erlang On Xen @ Kiev Functional Programming event, Aug 3 2013
Erlang On Xen @ Kiev Functional Programming event, Aug 3 2013Viktor Sovietov
 
So You Want to Protect Privacy: Now What?
So You Want to Protect Privacy: Now What?So You Want to Protect Privacy: Now What?
So You Want to Protect Privacy: Now What?Stuart Bailey
 
Android & Backup-Restore SMS
Android & Backup-Restore SMSAndroid & Backup-Restore SMS
Android & Backup-Restore SMStttoan
 
Twitter ppt18.12.2010
Twitter ppt18.12.2010Twitter ppt18.12.2010
Twitter ppt18.12.2010dianabhathena
 
Glass fish rubyconf-india-2010-Arun gupta
Glass fish rubyconf-india-2010-Arun gupta Glass fish rubyconf-india-2010-Arun gupta
Glass fish rubyconf-india-2010-Arun gupta ThoughtWorks
 
The Interface Of The Knowing Organization V02 (2009 11 21)Posted
The Interface Of The Knowing Organization V02 (2009 11 21)PostedThe Interface Of The Knowing Organization V02 (2009 11 21)Posted
The Interface Of The Knowing Organization V02 (2009 11 21)PostedStuart Bailey
 

En vedette (12)

Premium bikes
Premium bikesPremium bikes
Premium bikes
 
20130629 If you build it, will they visit [ala lita lightning talk]
20130629 If you build it, will they visit [ala lita lightning talk]20130629 If you build it, will they visit [ala lita lightning talk]
20130629 If you build it, will they visit [ala lita lightning talk]
 
Erlang On Xen @ Kiev Functional Programming event, Aug 3 2013
Erlang On Xen @ Kiev Functional Programming event, Aug 3 2013Erlang On Xen @ Kiev Functional Programming event, Aug 3 2013
Erlang On Xen @ Kiev Functional Programming event, Aug 3 2013
 
So You Want to Protect Privacy: Now What?
So You Want to Protect Privacy: Now What?So You Want to Protect Privacy: Now What?
So You Want to Protect Privacy: Now What?
 
Android & Backup-Restore SMS
Android & Backup-Restore SMSAndroid & Backup-Restore SMS
Android & Backup-Restore SMS
 
Hr slide 1
Hr slide 1Hr slide 1
Hr slide 1
 
Twitter ppt18.12.2010
Twitter ppt18.12.2010Twitter ppt18.12.2010
Twitter ppt18.12.2010
 
Extending rails
Extending railsExtending rails
Extending rails
 
Glass fish rubyconf-india-2010-Arun gupta
Glass fish rubyconf-india-2010-Arun gupta Glass fish rubyconf-india-2010-Arun gupta
Glass fish rubyconf-india-2010-Arun gupta
 
Musician ppt
Musician pptMusician ppt
Musician ppt
 
The Interface Of The Knowing Organization V02 (2009 11 21)Posted
The Interface Of The Knowing Organization V02 (2009 11 21)PostedThe Interface Of The Knowing Organization V02 (2009 11 21)Posted
The Interface Of The Knowing Organization V02 (2009 11 21)Posted
 
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job? Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
 

Similaire à Aman kingrubyoo pnew

Similaire à Aman kingrubyoo pnew (20)

oops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdfoops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdf
 
Object oriented programming tutorial
Object oriented programming tutorialObject oriented programming tutorial
Object oriented programming tutorial
 
Oops
OopsOops
Oops
 
Intro Ruby Classes Part I
Intro Ruby Classes Part IIntro Ruby Classes Part I
Intro Ruby Classes Part I
 
Object oriented programming CLASSES-AND-OBJECTS.pptx
Object oriented programming CLASSES-AND-OBJECTS.pptxObject oriented programming CLASSES-AND-OBJECTS.pptx
Object oriented programming CLASSES-AND-OBJECTS.pptx
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Chapter 8 java
Chapter 8 javaChapter 8 java
Chapter 8 java
 
Java programming -Object-Oriented Thinking- Inheritance
Java programming -Object-Oriented Thinking- InheritanceJava programming -Object-Oriented Thinking- Inheritance
Java programming -Object-Oriented Thinking- Inheritance
 
2.oop concept
2.oop concept2.oop concept
2.oop concept
 
01. design pattern
01. design pattern01. design pattern
01. design pattern
 
The Ruby Object Model by Rafael Magana
The Ruby Object Model by Rafael MaganaThe Ruby Object Model by Rafael Magana
The Ruby Object Model by Rafael Magana
 
Abstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAbstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and Interfaces
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Java
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Lecture 5.pptx
Lecture 5.pptxLecture 5.pptx
Lecture 5.pptx
 
Unusual C# - OOP
Unusual C# - OOPUnusual C# - OOP
Unusual C# - OOP
 
Ruby object model
Ruby object modelRuby object model
Ruby object model
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Ruby Interview Questions
Ruby Interview QuestionsRuby Interview Questions
Ruby Interview Questions
 
Review oop and ood
Review oop and oodReview oop and ood
Review oop and ood
 

Plus de ThoughtWorks

Online and Publishing casestudies
Online and Publishing casestudiesOnline and Publishing casestudies
Online and Publishing casestudiesThoughtWorks
 
Insurecom Case Study
Insurecom Case StudyInsurecom Case Study
Insurecom Case StudyThoughtWorks
 
Grameen Case Study
Grameen Case StudyGrameen Case Study
Grameen Case StudyThoughtWorks
 
Construction Techniques For Domain Specific Languages
Construction Techniques For Domain Specific LanguagesConstruction Techniques For Domain Specific Languages
Construction Techniques For Domain Specific LanguagesThoughtWorks
 
Concurrency patterns in Ruby
Concurrency patterns in RubyConcurrency patterns in Ruby
Concurrency patterns in RubyThoughtWorks
 
Concurrency patterns in Ruby
Concurrency patterns in RubyConcurrency patterns in Ruby
Concurrency patterns in RubyThoughtWorks
 
Lets build-ruby-app-server: Vineet tyagi
Lets build-ruby-app-server: Vineet tyagiLets build-ruby-app-server: Vineet tyagi
Lets build-ruby-app-server: Vineet tyagiThoughtWorks
 
Ruby on Rails versus Django - A newbie Web Developer's Perspective -Shreyank...
 Ruby on Rails versus Django - A newbie Web Developer's Perspective -Shreyank... Ruby on Rails versus Django - A newbie Web Developer's Perspective -Shreyank...
Ruby on Rails versus Django - A newbie Web Developer's Perspective -Shreyank...ThoughtWorks
 
Nick Sieger-Exploring Rails 3 Through Choices
Nick Sieger-Exploring Rails 3 Through Choices Nick Sieger-Exploring Rails 3 Through Choices
Nick Sieger-Exploring Rails 3 Through Choices ThoughtWorks
 
Present and Future of Programming Languages - ola bini
Present and Future of Programming Languages - ola biniPresent and Future of Programming Languages - ola bini
Present and Future of Programming Languages - ola biniThoughtWorks
 
The ruby on rails i18n core api-Neeraj Kumar
The ruby on rails i18n core api-Neeraj KumarThe ruby on rails i18n core api-Neeraj Kumar
The ruby on rails i18n core api-Neeraj KumarThoughtWorks
 
Ruby 124C41+ - Matz
Ruby 124C41+  - MatzRuby 124C41+  - Matz
Ruby 124C41+ - MatzThoughtWorks
 
Mac ruby to the max - Brendan G. Lim
Mac ruby to the max - Brendan G. LimMac ruby to the max - Brendan G. Lim
Mac ruby to the max - Brendan G. LimThoughtWorks
 
Project Fedena and Why Ruby on Rails - ArvindArvind G S
Project Fedena and Why Ruby on Rails - ArvindArvind G SProject Fedena and Why Ruby on Rails - ArvindArvind G S
Project Fedena and Why Ruby on Rails - ArvindArvind G SThoughtWorks
 
HadoopThe Hadoop Java Software Framework
HadoopThe Hadoop Java Software FrameworkHadoopThe Hadoop Java Software Framework
HadoopThe Hadoop Java Software FrameworkThoughtWorks
 
Bootstrapping iPhone Development
Bootstrapping iPhone DevelopmentBootstrapping iPhone Development
Bootstrapping iPhone DevelopmentThoughtWorks
 
DSL Construction rith Ruby
DSL Construction rith RubyDSL Construction rith Ruby
DSL Construction rith RubyThoughtWorks
 
Transitioning To Agile Webinar Presentation
Transitioning To Agile Webinar PresentationTransitioning To Agile Webinar Presentation
Transitioning To Agile Webinar PresentationThoughtWorks
 

Plus de ThoughtWorks (20)

Online and Publishing casestudies
Online and Publishing casestudiesOnline and Publishing casestudies
Online and Publishing casestudies
 
Insurecom Case Study
Insurecom Case StudyInsurecom Case Study
Insurecom Case Study
 
Grameen Case Study
Grameen Case StudyGrameen Case Study
Grameen Case Study
 
BFSI Case Sudies
BFSI Case SudiesBFSI Case Sudies
BFSI Case Sudies
 
Construction Techniques For Domain Specific Languages
Construction Techniques For Domain Specific LanguagesConstruction Techniques For Domain Specific Languages
Construction Techniques For Domain Specific Languages
 
Concurrency patterns in Ruby
Concurrency patterns in RubyConcurrency patterns in Ruby
Concurrency patterns in Ruby
 
Concurrency patterns in Ruby
Concurrency patterns in RubyConcurrency patterns in Ruby
Concurrency patterns in Ruby
 
Lets build-ruby-app-server: Vineet tyagi
Lets build-ruby-app-server: Vineet tyagiLets build-ruby-app-server: Vineet tyagi
Lets build-ruby-app-server: Vineet tyagi
 
Ruby on Rails versus Django - A newbie Web Developer's Perspective -Shreyank...
 Ruby on Rails versus Django - A newbie Web Developer's Perspective -Shreyank... Ruby on Rails versus Django - A newbie Web Developer's Perspective -Shreyank...
Ruby on Rails versus Django - A newbie Web Developer's Perspective -Shreyank...
 
Nick Sieger-Exploring Rails 3 Through Choices
Nick Sieger-Exploring Rails 3 Through Choices Nick Sieger-Exploring Rails 3 Through Choices
Nick Sieger-Exploring Rails 3 Through Choices
 
Present and Future of Programming Languages - ola bini
Present and Future of Programming Languages - ola biniPresent and Future of Programming Languages - ola bini
Present and Future of Programming Languages - ola bini
 
The ruby on rails i18n core api-Neeraj Kumar
The ruby on rails i18n core api-Neeraj KumarThe ruby on rails i18n core api-Neeraj Kumar
The ruby on rails i18n core api-Neeraj Kumar
 
Ruby 124C41+ - Matz
Ruby 124C41+  - MatzRuby 124C41+  - Matz
Ruby 124C41+ - Matz
 
Mac ruby to the max - Brendan G. Lim
Mac ruby to the max - Brendan G. LimMac ruby to the max - Brendan G. Lim
Mac ruby to the max - Brendan G. Lim
 
Project Fedena and Why Ruby on Rails - ArvindArvind G S
Project Fedena and Why Ruby on Rails - ArvindArvind G SProject Fedena and Why Ruby on Rails - ArvindArvind G S
Project Fedena and Why Ruby on Rails - ArvindArvind G S
 
HadoopThe Hadoop Java Software Framework
HadoopThe Hadoop Java Software FrameworkHadoopThe Hadoop Java Software Framework
HadoopThe Hadoop Java Software Framework
 
Bootstrapping iPhone Development
Bootstrapping iPhone DevelopmentBootstrapping iPhone Development
Bootstrapping iPhone Development
 
DSL Construction rith Ruby
DSL Construction rith RubyDSL Construction rith Ruby
DSL Construction rith Ruby
 
Cloud Computing
Cloud  ComputingCloud  Computing
Cloud Computing
 
Transitioning To Agile Webinar Presentation
Transitioning To Agile Webinar PresentationTransitioning To Agile Webinar Presentation
Transitioning To Agile Webinar Presentation
 

Aman kingrubyoo pnew