SlideShare a Scribd company logo
@vagnerzampieri

vgzampieri@gmail.com
Contando uma história com Orientação a Objeto
- Ruby, Python, C++, C#, VB.NET, Java, Object Pascal,
Objective-C e Smalltalk são exemplos de linguagens de
programação orientadas a objetos.

- ActionScript, ColdFusion, Javascript, PHP (a partir da versão 4.0),
Perl (a partir da versão 5) e Visual Basic (a partir da versão 4)
são exemplos de linguagens de programação com suporte
a orientação a objetos.
Conceitos básicos de O.O.

- Classe

- Objeto/instância

- Atributo

- Método

- Mensagem

- Herança

- Associação

- Encapsulamento
Vou falar dos 3 porquinhos
Objeto
Um objeto é capaz de armazenar estados através de seus atributos
e reagir a mensagens enviadas a ele, assim como se relacionar e
enviar mensagens a outros objetos. Um objeto está associado com
classe.

Ex.: Cícero, Heitor e Prático.
Atributos

São as características do objeto, basicamente a estrutura de
dados que vai representar a classe.

Ex.: Nome, peso, altura, idade
Classes
É um conjunto de objetos, a classe define o comportamento
dos objetos através de seus métodos.

Ex.: Animal, Pig, Wolf, House, TypeHouse
Vamos ver um pouco de código :)
Animal
 name
 weight
 height
 age

Pig < Animal
 house_id

Wolf < Animal

House
 type_house_id
 color
 length
 width
 height

TypeHouse
 name
1.9.3p194 :002 > p1 = Pig.create(name: 'Cícero')
 => #<Pig id: 1, name: "Cícero", type: "Pig", weight: nil, height: nil, age: nil,
created_at: "2012-12-12 21:55:14", updated_at: "2012-12-12 21:55:14", house_id: nil>

1.9.3p194 :012 > p2 = Pig.create(name: 'Heitor')
 => #<Pig id: 3, name: "Heitor", type: "Pig", weight: nil, height: nil, age: nil,
created_at: "2012-12-12 22:29:21", updated_at: "2012-12-12 22:29:21", house_id: nil>

1.9.3p194 :016 > p3 = Pig.create(name: 'Prático')
 => #<Pig id: 4, name: "Prático", type: "Pig", weight: nil, height: nil, age: nil,
created_at: "2012-12-12 22:35:09", updated_at: "2012-12-12 22:35:09", house_id: nil>
1.9.3p194 :005 > w = Wolf.create(name: "Lobo Mau")
 => #<Wolf id: 2, name: "Lobo Mau", type: "Wolf", weight: nil, height: nil, age: nil,
created_at: "2012-12-12 21:57:46", updated_at: "2012-12-12 21:57:46", house_id: nil>

1.9.3p194 :006 > w.speak
 => "Aaauuuuuuu"
type_house = TypeHouse.find 1
 => #<TypeHouse id: 1, name: "Palha", created_at: "2012-12-12 21:54:14",
updated_at: "2012-12-12 21:54:14">

1.9.3p194 :003 > p1.create_house(type_house_id: type_house.id, color: 'Amarela')
 => #<House id: 1, type_house_id: 1, color: "Amarelo", length: nil, width: nil, height: nil,
created_at: "2012-12-12 21:55:19", updated_at: "2012-12-12 21:55:19">

1.9.3p194 :004 > p1.save
 => true

class TypeHouse < ActiveRecord:Base
 has_many :houses
end

class House < ActiveRecorBase
 belongs_to :type_house
 has_many :pigs, dependent: :nullify
end

class Animal < ActiveRecord:Base
end

class Pig < Animal
 belongs_to :house
end
1.9.3p194 :011 > type_house = TypeHouse.find 2
 => #<TypeHouse id: 2, name: "Madeira", created_at: "2012-12-12 21:54:14",
updated_at: "2012-12-12 21:54:14">

1.9.3p194 :013 > p2.create_house(type_house_id: type_house.id, color: 'Marrom')
 => #<House id: 2, type_house_id: 2, color: "Marrom", length: nil, width: nil, height: nil,
created_at: "2012-12-12 22:29:54", updated_at: "2012-12-12 22:29:54">

1.9.3p194 :014 > p2.save
 => true
1.9.3p194 :015 > type_house = TypeHouse.find 3
 => #<TypeHouse id: 3, name: "Tijolo", created_at: "2012-12-12 21:54:14",
updated_at: "2012-12-12 21:54:14">

1.9.3p194 :017 > p3.create_house(type_house_id: type_house.id, color: 'Vermelha')
 => #<House id: 3, type_house_id: 3, color: "Vermelha", length: nil, width: nil, height: nil,
created_at: "2012-12-12 22:35:22", updated_at: "2012-12-12 22:35:22">

1.9.3p194 :018 > p3.save
 => true
1.9.3p194 :001 > w = Wolf.last
 Wolf Load (2.1ms) SELECT "animals".* FROM "animals" WHERE "animals"."type" IN ('Wolf')
 ORDER BY "animals"."id" DESC LIMIT 1
 => #<Wolf id: 4, name: "Lobo Mau", type: "Wolf", weight: nil, height: nil, age: nil,
created_at: "2012-12-12 23:55:38", updated_at: "2012-12-12 23:55:38", house_id: nil>

1.9.3p194 :002 > w.blow_the_straw_house

Vou soprar, vou soprar e sua casa vou derrubar

TypeHouse Load (15.3ms) SELECT "type_houses".* FROM "type_houses" WHERE "type_hous
House Load (1.9ms) SELECT "houses".* FROM "houses" WHERE "houses"."type_house_id" =
 (1.1ms) BEGIN
Pig Load (1.0ms) SELECT "animals".* FROM "animals" WHERE "animals"."type" IN ('Pig') AND
SQL (1.6ms) UPDATE "animals" SET "house_id" = NULL WHERE "animals"."type" IN ('Pig') AN
SQL (1.6ms) DELETE FROM "houses" WHERE "houses"."id" = $1 [["id", 1]]
 (20.1ms) COMMIT
=> [#<House id: 1, type_house_id: 1, color: "Marrom", length: nil, width: nil, height: nil, created_at
# encoding: UTF-8
class Wolf < Animal
 def speak
   "Aaauuuuuuu"
 end

 def blow_the_straw_house
  puts sentence_of_intimidation
  TypeHouse.destroy_houses_with 1
 end

 def blowing_wooden_house
  puts sentence_of_intimidation
  TypeHouse.destroy_houses_with 2
 end

 def blowing_brick_house
  puts sentence_of_intimidation
  puts "Porcos - Lobo tolo, minha casa é de tijolo"
 end

 private
 def sentence_of_intimidation
  "Lobo - Vou soprar, vou soprar e sua casa vou derrubar"
 end
end
class TypeHouse < ActiveRecord::Base
 attr_accessible :name

 has_many :houses

 validates :name, presence: true, uniqueness: true

 def self.destroy_houses_with id
  type_house = TypeHouse.find id
  type_house.houses.each do |house|
    house.destroy
  end
 end
end
1.9.3p194 :003 > w.blowing_wooden_house
Vou soprar, vou soprar e sua casa vou derrubar
  TypeHouse Load (0.7ms) SELECT "type_houses".* FROM "type_houses"
WHERE "type_houses"."id" = $1 LIMIT 1 [["id", 2]]
  House Load (0.8ms) SELECT "houses".* FROM "houses"
WHERE "houses"."type_house_id" = 2
  (0.2ms) BEGIN
  Pig Load (0.7ms) SELECT "animals".* FROM "animals" WHERE "animals"."type"
IN ('Pig') AND "animals"."house_id" = 2
  SQL (0.7ms) UPDATE "animals" SET "house_id" = NULL WHERE "animals"."type"
 IN ('Pig') AND "animals"."house_id" = 2 AND "animals"."id" IN (2)
  SQL (0.4ms) DELETE FROM "houses" WHERE "houses"."id" = $1 [["id", 2]]
  (17.3ms) COMMIT
 => [#<House id: 2, type_house_id: 2, color: "Vermelha", length: nil, width: nil, height: nil,
 created_at: "2012-12-12 23:55:37", updated_at: "2012-12-12 23:55:37">]
1.9.3p194 :002 > w.blowing_brick_house
Lobo - Vou soprar, vou soprar e sua casa vou derrubar
Porcos - Lobo tolo, minha casa é de tijolo
=> nil
1.9.3p194 :005 > w.chimney_climb
Lobo - vou comer esses porquinhos
 => nil
1.9.3p194 :006 > w.entering_the_chimney
ploft!!. O lobo caiu na panela de água fervente
  (0.3ms) BEGIN
 SQL (10.8ms) DELETE FROM "animals" WHERE "animals"."type" IN ('Wolf')
AND "animals"."id" = $1 [["id", 4]]
  (21.6ms) COMMIT
 => #<Wolf id: 4, name: "Lobo Mau", type: "Wolf", weight: nil, height: nil, age: nil,
created_at: "2012-12-14 19:56:59", updated_at: "2012-12-14 19:56:59", house_id: nil>
1.9.3p194 :001 > Pig.singing
Quem tem medo do lobo mau, lobo mau, lobo mau ...
 => nil
Contando uma história com O.O.

More Related Content

What's hot

Rails Model Basics
Rails Model BasicsRails Model Basics
Rails Model Basics
James Gray
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Groupkchodorow
 
DataMapper @ RubyEnRails2009
DataMapper @ RubyEnRails2009DataMapper @ RubyEnRails2009
DataMapper @ RubyEnRails2009
Dirkjan Bussink
 
Cleaner, Leaner, Meaner: Refactoring your jQuery
Cleaner, Leaner, Meaner: Refactoring your jQueryCleaner, Leaner, Meaner: Refactoring your jQuery
Cleaner, Leaner, Meaner: Refactoring your jQueryRebecca Murphey
 
How to use MongoDB with CakePHP
How to use MongoDB with CakePHPHow to use MongoDB with CakePHP
How to use MongoDB with CakePHP
ichikaway
 
MongoDB With Style
MongoDB With StyleMongoDB With Style
MongoDB With Style
Gabriele Lana
 
OO Perl with Moose
OO Perl with MooseOO Perl with Moose
OO Perl with MooseNelo Onyiah
 
MongoD Essentials
MongoD EssentialsMongoD Essentials
MongoD Essentials
zahid-mian
 
Introduction To Moose
Introduction To MooseIntroduction To Moose
Introduction To Moose
Mike Whitaker
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
Scott Leberknight
 
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法Tomohiro Nishimura
 
Moose (Perl 5)
Moose (Perl 5)Moose (Perl 5)
Moose (Perl 5)
xSawyer
 
MongoDB
MongoDBMongoDB
MongoDB
Steve Klabnik
 
Geospatial Indexing and Querying with MongoDB
Geospatial Indexing and Querying with MongoDBGeospatial Indexing and Querying with MongoDB
Geospatial Indexing and Querying with MongoDB
Grant Goodale
 
Introduction to Moose
Introduction to MooseIntroduction to Moose
Introduction to Moose
thashaa
 
Native json in the Cache' ObjectScript 2016.*
Native json in the Cache' ObjectScript 2016.*Native json in the Cache' ObjectScript 2016.*
Native json in the Cache' ObjectScript 2016.*
Timur Safin
 
The Ring programming language version 1.10 book - Part 56 of 212
The Ring programming language version 1.10 book - Part 56 of 212The Ring programming language version 1.10 book - Part 56 of 212
The Ring programming language version 1.10 book - Part 56 of 212
Mahmoud Samir Fayed
 
To infinity and beyond
To infinity and beyondTo infinity and beyond
To infinity and beyond
clintongormley
 
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제홍준 김
 
Building DSLs with Groovy
Building DSLs with GroovyBuilding DSLs with Groovy
Building DSLs with Groovy
Sten Anderson
 

What's hot (20)

Rails Model Basics
Rails Model BasicsRails Model Basics
Rails Model Basics
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Group
 
DataMapper @ RubyEnRails2009
DataMapper @ RubyEnRails2009DataMapper @ RubyEnRails2009
DataMapper @ RubyEnRails2009
 
Cleaner, Leaner, Meaner: Refactoring your jQuery
Cleaner, Leaner, Meaner: Refactoring your jQueryCleaner, Leaner, Meaner: Refactoring your jQuery
Cleaner, Leaner, Meaner: Refactoring your jQuery
 
How to use MongoDB with CakePHP
How to use MongoDB with CakePHPHow to use MongoDB with CakePHP
How to use MongoDB with CakePHP
 
MongoDB With Style
MongoDB With StyleMongoDB With Style
MongoDB With Style
 
OO Perl with Moose
OO Perl with MooseOO Perl with Moose
OO Perl with Moose
 
MongoD Essentials
MongoD EssentialsMongoD Essentials
MongoD Essentials
 
Introduction To Moose
Introduction To MooseIntroduction To Moose
Introduction To Moose
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法
 
Moose (Perl 5)
Moose (Perl 5)Moose (Perl 5)
Moose (Perl 5)
 
MongoDB
MongoDBMongoDB
MongoDB
 
Geospatial Indexing and Querying with MongoDB
Geospatial Indexing and Querying with MongoDBGeospatial Indexing and Querying with MongoDB
Geospatial Indexing and Querying with MongoDB
 
Introduction to Moose
Introduction to MooseIntroduction to Moose
Introduction to Moose
 
Native json in the Cache' ObjectScript 2016.*
Native json in the Cache' ObjectScript 2016.*Native json in the Cache' ObjectScript 2016.*
Native json in the Cache' ObjectScript 2016.*
 
The Ring programming language version 1.10 book - Part 56 of 212
The Ring programming language version 1.10 book - Part 56 of 212The Ring programming language version 1.10 book - Part 56 of 212
The Ring programming language version 1.10 book - Part 56 of 212
 
To infinity and beyond
To infinity and beyondTo infinity and beyond
To infinity and beyond
 
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
 
Building DSLs with Groovy
Building DSLs with GroovyBuilding DSLs with Groovy
Building DSLs with Groovy
 

Viewers also liked

Evaluating Mobile Options For Libraries - CIL 2012
Evaluating Mobile Options For Libraries - CIL 2012Evaluating Mobile Options For Libraries - CIL 2012
Evaluating Mobile Options For Libraries - CIL 2012amyhannah84
 
Dienstenpakketten
DienstenpakkettenDienstenpakketten
Dienstenpakketten
renthousepro
 
Graphical representation: a necessary evil?
Graphical representation: a necessary evil?Graphical representation: a necessary evil?
Graphical representation: a necessary evil?Sidhartha Jatar
 
My Name Is Amy Byers Figgs
My Name Is Amy Byers FiggsMy Name Is Amy Byers Figgs
My Name Is Amy Byers Figgs
AmyFiggs
 
Brown Fat, Rajesh kumar mukherjee[1] (b.pharmacy 1st sem ppt)
Brown Fat, Rajesh kumar mukherjee[1] (b.pharmacy 1st sem ppt)Brown Fat, Rajesh kumar mukherjee[1] (b.pharmacy 1st sem ppt)
Brown Fat, Rajesh kumar mukherjee[1] (b.pharmacy 1st sem ppt)
Rajesh Kumar Mukherjee
 
Alemania, presentación
Alemania, presentaciónAlemania, presentación
Alemania, presentaciónprimeroeg2
 
Catalogo Tonic Life 2011
Catalogo Tonic Life 2011Catalogo Tonic Life 2011
Catalogo Tonic Life 2011toniclifetoluca
 
Кулинарная мастеркая Just cook
Кулинарная мастеркая Just cookКулинарная мастеркая Just cook
Кулинарная мастеркая Just cook
Мурад Калаев
 
Things to do with BYOD
Things to do with BYODThings to do with BYOD
Things to do with BYOD
karen-fleming
 
Expertise bij Renthouse
Expertise bij RenthouseExpertise bij Renthouse
Expertise bij Renthouserenthousepro
 
Oscon11 geeking in_a_cabin
Oscon11 geeking in_a_cabinOscon11 geeking in_a_cabin
Oscon11 geeking in_a_cabinRyo Chijiiwa
 
Rendementvol Verhuur
Rendementvol VerhuurRendementvol Verhuur
Rendementvol Verhuur
renthousepro
 
Economic crisis - Punjabis - 2008
Economic crisis - Punjabis - 2008Economic crisis - Punjabis - 2008
Economic crisis - Punjabis - 2008E P John
 
Probiotics, rajesh kumar mukherjee[1] (b.pharmacy 2nd sem ppt)
Probiotics, rajesh kumar mukherjee[1] (b.pharmacy 2nd sem ppt)Probiotics, rajesh kumar mukherjee[1] (b.pharmacy 2nd sem ppt)
Probiotics, rajesh kumar mukherjee[1] (b.pharmacy 2nd sem ppt)
Rajesh Kumar Mukherjee
 
FRX® Exterior Fire Retardant Wood
FRX® Exterior Fire Retardant WoodFRX® Exterior Fire Retardant Wood
FRX® Exterior Fire Retardant Wood
WolmanizedWood
 
solubilization, (b.pharmacy 7th sem ppt) Rajesh ku mukherjee
solubilization, (b.pharmacy 7th sem ppt) Rajesh ku mukherjeesolubilization, (b.pharmacy 7th sem ppt) Rajesh ku mukherjee
solubilization, (b.pharmacy 7th sem ppt) Rajesh ku mukherjee
Rajesh Kumar Mukherjee
 

Viewers also liked (20)

Evaluating Mobile Options For Libraries - CIL 2012
Evaluating Mobile Options For Libraries - CIL 2012Evaluating Mobile Options For Libraries - CIL 2012
Evaluating Mobile Options For Libraries - CIL 2012
 
Dienstenpakketten
DienstenpakkettenDienstenpakketten
Dienstenpakketten
 
Креативный процеSS
Креативный процеSSКреативный процеSS
Креативный процеSS
 
Graphical representation: a necessary evil?
Graphical representation: a necessary evil?Graphical representation: a necessary evil?
Graphical representation: a necessary evil?
 
Camtasia 940
Camtasia 940Camtasia 940
Camtasia 940
 
My Name Is Amy Byers Figgs
My Name Is Amy Byers FiggsMy Name Is Amy Byers Figgs
My Name Is Amy Byers Figgs
 
Brown Fat, Rajesh kumar mukherjee[1] (b.pharmacy 1st sem ppt)
Brown Fat, Rajesh kumar mukherjee[1] (b.pharmacy 1st sem ppt)Brown Fat, Rajesh kumar mukherjee[1] (b.pharmacy 1st sem ppt)
Brown Fat, Rajesh kumar mukherjee[1] (b.pharmacy 1st sem ppt)
 
Alemania, presentación
Alemania, presentaciónAlemania, presentación
Alemania, presentación
 
Catalogo Tonic Life 2011
Catalogo Tonic Life 2011Catalogo Tonic Life 2011
Catalogo Tonic Life 2011
 
Кулинарная мастеркая Just cook
Кулинарная мастеркая Just cookКулинарная мастеркая Just cook
Кулинарная мастеркая Just cook
 
Things to do with BYOD
Things to do with BYODThings to do with BYOD
Things to do with BYOD
 
Expertise bij Renthouse
Expertise bij RenthouseExpertise bij Renthouse
Expertise bij Renthouse
 
Oscon11 geeking in_a_cabin
Oscon11 geeking in_a_cabinOscon11 geeking in_a_cabin
Oscon11 geeking in_a_cabin
 
Rendementvol Verhuur
Rendementvol VerhuurRendementvol Verhuur
Rendementvol Verhuur
 
Economic crisis - Punjabis - 2008
Economic crisis - Punjabis - 2008Economic crisis - Punjabis - 2008
Economic crisis - Punjabis - 2008
 
pay army
pay armypay army
pay army
 
Final fpk
Final fpkFinal fpk
Final fpk
 
Probiotics, rajesh kumar mukherjee[1] (b.pharmacy 2nd sem ppt)
Probiotics, rajesh kumar mukherjee[1] (b.pharmacy 2nd sem ppt)Probiotics, rajesh kumar mukherjee[1] (b.pharmacy 2nd sem ppt)
Probiotics, rajesh kumar mukherjee[1] (b.pharmacy 2nd sem ppt)
 
FRX® Exterior Fire Retardant Wood
FRX® Exterior Fire Retardant WoodFRX® Exterior Fire Retardant Wood
FRX® Exterior Fire Retardant Wood
 
solubilization, (b.pharmacy 7th sem ppt) Rajesh ku mukherjee
solubilization, (b.pharmacy 7th sem ppt) Rajesh ku mukherjeesolubilization, (b.pharmacy 7th sem ppt) Rajesh ku mukherjee
solubilization, (b.pharmacy 7th sem ppt) Rajesh ku mukherjee
 

Similar to Contando uma história com O.O.

Moose - YAPC::NA 2012
Moose - YAPC::NA 2012Moose - YAPC::NA 2012
Moose - YAPC::NA 2012
xSawyer
 
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010Alex Sharp
 
Indexing thousands of writes per second with redis
Indexing thousands of writes per second with redisIndexing thousands of writes per second with redis
Indexing thousands of writes per second with redis
pauldix
 
Running Production MongoDB Lightning Talk
Running Production MongoDB Lightning TalkRunning Production MongoDB Lightning Talk
Running Production MongoDB Lightning Talk
chrisckchang
 
第二讲 预备-Python基礎
第二讲 预备-Python基礎第二讲 预备-Python基礎
第二讲 预备-Python基礎
anzhong70
 
第二讲 Python基礎
第二讲 Python基礎第二讲 Python基礎
第二讲 Python基礎
juzihua1102
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Masahiro Nagano
 
Eve - REST API for Humans™
Eve - REST API for Humans™Eve - REST API for Humans™
Eve - REST API for Humans™
Nicola Iarocci
 
Practical Ruby Projects (Alex Sharp)
Practical Ruby Projects (Alex Sharp)Practical Ruby Projects (Alex Sharp)
Practical Ruby Projects (Alex Sharp)MongoSF
 
Practical Ruby Projects with MongoDB - MongoSF
Practical Ruby Projects with MongoDB - MongoSFPractical Ruby Projects with MongoDB - MongoSF
Practical Ruby Projects with MongoDB - MongoSF
Alex Sharp
 
Write better python code with these 10 tricks | by yong cui, ph.d. | aug, 202...
Write better python code with these 10 tricks | by yong cui, ph.d. | aug, 202...Write better python code with these 10 tricks | by yong cui, ph.d. | aug, 202...
Write better python code with these 10 tricks | by yong cui, ph.d. | aug, 202...
amit kuraria
 
Coffeescript a z
Coffeescript a zCoffeescript a z
Coffeescript a zStarbuildr
 
ETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDBETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDB
MongoDB
 
Practical Ruby Projects With Mongo Db
Practical Ruby Projects With Mongo DbPractical Ruby Projects With Mongo Db
Practical Ruby Projects With Mongo Db
Alex Sharp
 
Values
ValuesValues
Values
BenEddy
 
Propel sfugmd
Propel sfugmdPropel sfugmd
Propel sfugmdiKlaus
 

Similar to Contando uma história com O.O. (16)

Moose - YAPC::NA 2012
Moose - YAPC::NA 2012Moose - YAPC::NA 2012
Moose - YAPC::NA 2012
 
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
 
Indexing thousands of writes per second with redis
Indexing thousands of writes per second with redisIndexing thousands of writes per second with redis
Indexing thousands of writes per second with redis
 
Running Production MongoDB Lightning Talk
Running Production MongoDB Lightning TalkRunning Production MongoDB Lightning Talk
Running Production MongoDB Lightning Talk
 
第二讲 预备-Python基礎
第二讲 预备-Python基礎第二讲 预备-Python基礎
第二讲 预备-Python基礎
 
第二讲 Python基礎
第二讲 Python基礎第二讲 Python基礎
第二讲 Python基礎
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 
Eve - REST API for Humans™
Eve - REST API for Humans™Eve - REST API for Humans™
Eve - REST API for Humans™
 
Practical Ruby Projects (Alex Sharp)
Practical Ruby Projects (Alex Sharp)Practical Ruby Projects (Alex Sharp)
Practical Ruby Projects (Alex Sharp)
 
Practical Ruby Projects with MongoDB - MongoSF
Practical Ruby Projects with MongoDB - MongoSFPractical Ruby Projects with MongoDB - MongoSF
Practical Ruby Projects with MongoDB - MongoSF
 
Write better python code with these 10 tricks | by yong cui, ph.d. | aug, 202...
Write better python code with these 10 tricks | by yong cui, ph.d. | aug, 202...Write better python code with these 10 tricks | by yong cui, ph.d. | aug, 202...
Write better python code with these 10 tricks | by yong cui, ph.d. | aug, 202...
 
Coffeescript a z
Coffeescript a zCoffeescript a z
Coffeescript a z
 
ETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDBETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDB
 
Practical Ruby Projects With Mongo Db
Practical Ruby Projects With Mongo DbPractical Ruby Projects With Mongo Db
Practical Ruby Projects With Mongo Db
 
Values
ValuesValues
Values
 
Propel sfugmd
Propel sfugmdPropel sfugmd
Propel sfugmd
 

Recently uploaded

GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 

Recently uploaded (20)

GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 

Contando uma história com O.O.

  • 2. Contando uma história com Orientação a Objeto
  • 3. - Ruby, Python, C++, C#, VB.NET, Java, Object Pascal, Objective-C e Smalltalk são exemplos de linguagens de programação orientadas a objetos. - ActionScript, ColdFusion, Javascript, PHP (a partir da versão 4.0), Perl (a partir da versão 5) e Visual Basic (a partir da versão 4) são exemplos de linguagens de programação com suporte a orientação a objetos.
  • 4. Conceitos básicos de O.O. - Classe - Objeto/instância - Atributo - Método - Mensagem - Herança - Associação - Encapsulamento
  • 5. Vou falar dos 3 porquinhos
  • 6. Objeto Um objeto é capaz de armazenar estados através de seus atributos e reagir a mensagens enviadas a ele, assim como se relacionar e enviar mensagens a outros objetos. Um objeto está associado com classe. Ex.: Cícero, Heitor e Prático.
  • 7. Atributos São as características do objeto, basicamente a estrutura de dados que vai representar a classe. Ex.: Nome, peso, altura, idade
  • 8. Classes É um conjunto de objetos, a classe define o comportamento dos objetos através de seus métodos. Ex.: Animal, Pig, Wolf, House, TypeHouse
  • 9. Vamos ver um pouco de código :)
  • 10. Animal name weight height age Pig < Animal house_id Wolf < Animal House type_house_id color length width height TypeHouse name
  • 11. 1.9.3p194 :002 > p1 = Pig.create(name: 'Cícero') => #<Pig id: 1, name: "Cícero", type: "Pig", weight: nil, height: nil, age: nil, created_at: "2012-12-12 21:55:14", updated_at: "2012-12-12 21:55:14", house_id: nil> 1.9.3p194 :012 > p2 = Pig.create(name: 'Heitor') => #<Pig id: 3, name: "Heitor", type: "Pig", weight: nil, height: nil, age: nil, created_at: "2012-12-12 22:29:21", updated_at: "2012-12-12 22:29:21", house_id: nil> 1.9.3p194 :016 > p3 = Pig.create(name: 'Prático') => #<Pig id: 4, name: "Prático", type: "Pig", weight: nil, height: nil, age: nil, created_at: "2012-12-12 22:35:09", updated_at: "2012-12-12 22:35:09", house_id: nil>
  • 12. 1.9.3p194 :005 > w = Wolf.create(name: "Lobo Mau") => #<Wolf id: 2, name: "Lobo Mau", type: "Wolf", weight: nil, height: nil, age: nil, created_at: "2012-12-12 21:57:46", updated_at: "2012-12-12 21:57:46", house_id: nil> 1.9.3p194 :006 > w.speak => "Aaauuuuuuu"
  • 13. type_house = TypeHouse.find 1 => #<TypeHouse id: 1, name: "Palha", created_at: "2012-12-12 21:54:14", updated_at: "2012-12-12 21:54:14"> 1.9.3p194 :003 > p1.create_house(type_house_id: type_house.id, color: 'Amarela') => #<House id: 1, type_house_id: 1, color: "Amarelo", length: nil, width: nil, height: nil, created_at: "2012-12-12 21:55:19", updated_at: "2012-12-12 21:55:19"> 1.9.3p194 :004 > p1.save => true class TypeHouse < ActiveRecord:Base has_many :houses end class House < ActiveRecorBase belongs_to :type_house has_many :pigs, dependent: :nullify end class Animal < ActiveRecord:Base end class Pig < Animal belongs_to :house end
  • 14. 1.9.3p194 :011 > type_house = TypeHouse.find 2 => #<TypeHouse id: 2, name: "Madeira", created_at: "2012-12-12 21:54:14", updated_at: "2012-12-12 21:54:14"> 1.9.3p194 :013 > p2.create_house(type_house_id: type_house.id, color: 'Marrom') => #<House id: 2, type_house_id: 2, color: "Marrom", length: nil, width: nil, height: nil, created_at: "2012-12-12 22:29:54", updated_at: "2012-12-12 22:29:54"> 1.9.3p194 :014 > p2.save => true
  • 15. 1.9.3p194 :015 > type_house = TypeHouse.find 3 => #<TypeHouse id: 3, name: "Tijolo", created_at: "2012-12-12 21:54:14", updated_at: "2012-12-12 21:54:14"> 1.9.3p194 :017 > p3.create_house(type_house_id: type_house.id, color: 'Vermelha') => #<House id: 3, type_house_id: 3, color: "Vermelha", length: nil, width: nil, height: nil, created_at: "2012-12-12 22:35:22", updated_at: "2012-12-12 22:35:22"> 1.9.3p194 :018 > p3.save => true
  • 16. 1.9.3p194 :001 > w = Wolf.last Wolf Load (2.1ms) SELECT "animals".* FROM "animals" WHERE "animals"."type" IN ('Wolf') ORDER BY "animals"."id" DESC LIMIT 1 => #<Wolf id: 4, name: "Lobo Mau", type: "Wolf", weight: nil, height: nil, age: nil, created_at: "2012-12-12 23:55:38", updated_at: "2012-12-12 23:55:38", house_id: nil> 1.9.3p194 :002 > w.blow_the_straw_house Vou soprar, vou soprar e sua casa vou derrubar TypeHouse Load (15.3ms) SELECT "type_houses".* FROM "type_houses" WHERE "type_hous House Load (1.9ms) SELECT "houses".* FROM "houses" WHERE "houses"."type_house_id" = (1.1ms) BEGIN Pig Load (1.0ms) SELECT "animals".* FROM "animals" WHERE "animals"."type" IN ('Pig') AND SQL (1.6ms) UPDATE "animals" SET "house_id" = NULL WHERE "animals"."type" IN ('Pig') AN SQL (1.6ms) DELETE FROM "houses" WHERE "houses"."id" = $1 [["id", 1]] (20.1ms) COMMIT => [#<House id: 1, type_house_id: 1, color: "Marrom", length: nil, width: nil, height: nil, created_at
  • 17. # encoding: UTF-8 class Wolf < Animal def speak "Aaauuuuuuu" end def blow_the_straw_house puts sentence_of_intimidation TypeHouse.destroy_houses_with 1 end def blowing_wooden_house puts sentence_of_intimidation TypeHouse.destroy_houses_with 2 end def blowing_brick_house puts sentence_of_intimidation puts "Porcos - Lobo tolo, minha casa é de tijolo" end private def sentence_of_intimidation "Lobo - Vou soprar, vou soprar e sua casa vou derrubar" end end
  • 18. class TypeHouse < ActiveRecord::Base attr_accessible :name has_many :houses validates :name, presence: true, uniqueness: true def self.destroy_houses_with id type_house = TypeHouse.find id type_house.houses.each do |house| house.destroy end end end
  • 19. 1.9.3p194 :003 > w.blowing_wooden_house Vou soprar, vou soprar e sua casa vou derrubar TypeHouse Load (0.7ms) SELECT "type_houses".* FROM "type_houses" WHERE "type_houses"."id" = $1 LIMIT 1 [["id", 2]] House Load (0.8ms) SELECT "houses".* FROM "houses" WHERE "houses"."type_house_id" = 2 (0.2ms) BEGIN Pig Load (0.7ms) SELECT "animals".* FROM "animals" WHERE "animals"."type" IN ('Pig') AND "animals"."house_id" = 2 SQL (0.7ms) UPDATE "animals" SET "house_id" = NULL WHERE "animals"."type" IN ('Pig') AND "animals"."house_id" = 2 AND "animals"."id" IN (2) SQL (0.4ms) DELETE FROM "houses" WHERE "houses"."id" = $1 [["id", 2]] (17.3ms) COMMIT => [#<House id: 2, type_house_id: 2, color: "Vermelha", length: nil, width: nil, height: nil, created_at: "2012-12-12 23:55:37", updated_at: "2012-12-12 23:55:37">]
  • 20. 1.9.3p194 :002 > w.blowing_brick_house Lobo - Vou soprar, vou soprar e sua casa vou derrubar Porcos - Lobo tolo, minha casa é de tijolo => nil
  • 21. 1.9.3p194 :005 > w.chimney_climb Lobo - vou comer esses porquinhos => nil 1.9.3p194 :006 > w.entering_the_chimney ploft!!. O lobo caiu na panela de água fervente (0.3ms) BEGIN SQL (10.8ms) DELETE FROM "animals" WHERE "animals"."type" IN ('Wolf') AND "animals"."id" = $1 [["id", 4]] (21.6ms) COMMIT => #<Wolf id: 4, name: "Lobo Mau", type: "Wolf", weight: nil, height: nil, age: nil, created_at: "2012-12-14 19:56:59", updated_at: "2012-12-14 19:56:59", house_id: nil>
  • 22. 1.9.3p194 :001 > Pig.singing Quem tem medo do lobo mau, lobo mau, lobo mau ... => nil