Published on March 23, 2010
Ruby OOP: Objects over Classes
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.
Private access modifier is object-level.
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.
Objects are first-class citizens.
Classes are useful but secondary.
Thank you firstname.lastname@example.org http://www.wikyblog.com/AmanKing
Presentación que realice en el Evento Nacional de Gobierno Abierto, realizado los ...
In this presentation we will describe our experience developing with a highly dyna...
Presentation to the LITA Forum 7th November 2014 Albuquerque, NM
Un recorrido por los cambios que nos generará el wearabletech en el futuro
Um paralelo entre as novidades & mercado em Wearable Computing e Tecnologias Assis...
Object-oriented programming in Ruby. ... In a OOP program, we create objects. ... Over the years users are accustomed to using specific methods and ...
Why Object.class == Class in Ruby? ... two parallel hierarchies of classes and ... package ruby objects into an array and iterate over them in a ...
Ruby as a “pure” object oriented language — inconsistency with Ruby ... or socket classes. ... as in OOP) for methods that are used all over ...
Object-oriented programming (OOP) ... classes and objects can be composed using ... and libraries such as Java Data Objects and Ruby on Rails ...
... modeled in code by "objects." In OOP, ... basic code to set up classes in Ruby. ... and paste it over to the Actress class. What OOP concept did we ...
Ruby OOP - Objects over Classes. by Aman King. Asked to design an object-oriented solution to a problem, ... A language like Ruby, however, ...
... (OOP) is just plain weird ... Ruby also has another construct that ... this should only serve as a way for you to bridge over to understanding classes ...
Object Oriented Ruby ... A beginner's tutorial containing complete knowledge of Ruby Syntax Syntax, Classes ... Ruby does not apply any access control over ...
... meaning that objects are instances of classes, ... OOP Popularity Over Time. ... Classes, Interfaces and OOP.