SlideShare a Scribd company logo
1 of 20
Paradigmas de Linguagens de Programação Paradigma Orientado a Objetos Aula #7 (CopyLeft)2009 - Ismar Frango ismar@mackenzie.br
“ There are only two kinds of languages: the ones people complain about and the ones nobody uses.” Bjarne Stroustrup Binding em LOO
 
 
22/09/09
 
invariância covariância contravariância   
 
 
22/09/09 ?
?
Asteroid SpaceShip Thing Dispatching em LOO
abstract class   Thing  { public abstract void   collideWith ( Thing  other); } class   Asteroid  extends  Thing  { public void  collideWith ( Thing  other) { if (other  instanceof   Asteroid ) { // handle Asteroid-Asteroid collision } else if (other  instanceof   Spaceship ) { // handle Asteroid-Spaceship collision } } } class   Spaceship  extends  Thing  { public void   collideWith ( Thing  other) { if  (other  instanceof   Asteroid ) { // handle Spaceship-Asteroid collision } else  if (other  instanceof   Spaceship ) { // handle Spaceship-Spaceship collision } } }
abstract class  Thing { public abstract void   collideWith ( Thing  other); } class  Asteroid  extends  Thing { public void   collideWith ( Asteroid  other) { System.out.println("handle Asteroid-Asteroid collision"); } public void   collideWith ( Spaceship  s) { System.out.println("handle Asteroid-Spaceship collision"); } } class Spaceship extends Thing { public void   collideWith ( Asteroid  a) { System.out.println("handle Spaceship-Asteroid collision"); } public void   collideWith ( Spaceship  other) { System.out.println("handle Spaceship-Spaceship collision"); } } 
abstract class  Thing { public abstract void   collideWith ( Thing  other); } class  Asteroid  extends  Thing { public void   collideWith ( Thing  other) {} public void   collideWith ( Asteroid  other) { System.out.println("handle Asteroid-Asteroid collision"); } public void   collideWith ( Spaceship  s) { System.out.println("handle Asteroid-Spaceship collision"); } } class Spaceship extends Thing { public void   collideWith ( Thing  other) {} public void   collideWith ( Asteroid  a) { System.out.println("handle Spaceship-Asteroid collision"); } public void   collideWith ( Spaceship  other) { System.out.println("handle Spaceship-Spaceship collision"); } } 
Asteroid ExplodingAsteroid SpaceShip GiantSpaceShip Thing
class   SpaceShip  {}; class   GiantSpaceShip  :  public  SpaceShip {}; class   Asteroid  { public : virtual void   CollideWith (SpaceShip&) { cout << &quot;Asteroid hit a SpaceShip&quot; << endl; } virtual void   CollideWith (GiantSpaceShip&) { cout << &quot;Asteroid hit a GiantSpaceShip&quot; << endl; } }; class   ExplodingAsteroid  :  public   Asteroid  { public : virtual void   CollideWith (SpaceShip&) { cout << &quot;ExplodingAsteroid hit a SpaceShip&quot; << endl; } virtual void   CollideWith (GiantSpaceShip&) { cout << &quot;ExplodingAsteroid hit a GiantSpaceShip&quot; << endl; } };
class   SpaceShip  {}; class   GiantSpaceShip  :  public  SpaceShip {}; class   Asteroid  { public : virtual void   CollideWith (SpaceShip&) { cout << &quot;Asteroid hit a SpaceShip&quot; << endl; } virtual void   CollideWith (GiantSpaceShip&) { cout << &quot;Asteroid hit a GiantSpaceShip&quot; << endl; } }; class   ExplodingAsteroid  :  public   Asteroid  { public : virtual void   CollideWith (SpaceShip&) { cout << &quot;ExplodingAsteroid hit a SpaceShip&quot; << endl; } virtual void   CollideWith (GiantSpaceShip&) { cout << &quot;ExplodingAsteroid hit a GiantSpaceShip&quot; << endl; } }; Asteroid  theAsteroid;  SpaceShip  theSpaceShip;  GiantSpaceShip  theGiantSpaceShip; theAsteroid . CollideWith (theSpaceShip);  theAsteroid . CollideWith (theGiantSpaceShip);   Asteroid * theAsteroidReference =  new   ExplodingAsteroid ();  theAsteroidReference -> CollideWith (theSpaceShip);  theAsteroidReference -> CollideWith (theGiantSpaceShip);  SpaceShip & theSpaceShipReference = theGiantSpaceShip;  theAsteroid . CollideWith (theSpaceShipReference);  theAsteroidReference -> CollideWith (theSpaceShipReference);
class   SpaceShip   { virtual void   CollideWith ( Asteroid & inAsteroid)  { inAsteroid. CollideWith (* this ); }  }; class   GiantSpaceShip  :  public  SpaceShip {}; Asteroid hit a SpaceShip ExplodingAsteroid hit a SpaceShip SpaceShip & theSpaceShipReference = theGiantSpaceShip;  Asteroid & theAsteroidReference = theExplodingAsteroid;  theSpaceShipReference. CollideWith (theAsteroid);  theSpaceShipReference. CollideWith (theAsteroidReference);   class   SpaceShip   { virtual void   CollideWith ( Asteroid & inAsteroid)  { inAsteroid. CollideWith (* this ); }  }; class   GiantSpaceShip  :  public  SpaceShip  { virtual void   CollideWith ( Asteroid & inAsteroid)  { inAsteroid. CollideWith (* this ); }  }; Asteroid hit a GiantSpaceShip ExplodingAsteroid hit a GiantSpaceShip
O Padrão Visitor

More Related Content

Viewers also liked

Paradigmas de Linguagens de Programacao- Aula #8
Paradigmas de Linguagens de Programacao- Aula #8Paradigmas de Linguagens de Programacao- Aula #8
Paradigmas de Linguagens de Programacao- Aula #8Ismar Silveira
 
Paradigmas de linguagens de programacao - aula#10
Paradigmas de linguagens de programacao - aula#10Paradigmas de linguagens de programacao - aula#10
Paradigmas de linguagens de programacao - aula#10Ismar Silveira
 
Apostila sistema operacional cor capa ficha 2011 02 04
Apostila sistema operacional cor capa ficha 2011 02 04Apostila sistema operacional cor capa ficha 2011 02 04
Apostila sistema operacional cor capa ficha 2011 02 04MatheusRpz
 
Paradigmas de Linguagens de Programacao - Aula #1
Paradigmas de Linguagens de Programacao - Aula #1Paradigmas de Linguagens de Programacao - Aula #1
Paradigmas de Linguagens de Programacao - Aula #1Ismar Silveira
 
Introdução à Computação Aula 01 - Apresentação
Introdução à Computação  Aula 01 - ApresentaçãoIntrodução à Computação  Aula 01 - Apresentação
Introdução à Computação Aula 01 - ApresentaçãoLeinylson Fontinele
 
Introducao ambiente windows
Introducao ambiente windowsIntroducao ambiente windows
Introducao ambiente windowsMatheusRpz
 
Paradigmas de Linguagens de programacao - Aula #2
Paradigmas de Linguagens de programacao - Aula #2Paradigmas de Linguagens de programacao - Aula #2
Paradigmas de Linguagens de programacao - Aula #2Ismar Silveira
 
A Linguagem Lua e suas Aplicações em Jogos
A Linguagem Lua e suas Aplicações em JogosA Linguagem Lua e suas Aplicações em Jogos
A Linguagem Lua e suas Aplicações em Jogoselliando dias
 
Apostila Algoritmos e Estrutura de Dados (AEDS)
Apostila Algoritmos e Estrutura de Dados (AEDS)Apostila Algoritmos e Estrutura de Dados (AEDS)
Apostila Algoritmos e Estrutura de Dados (AEDS)Ricardo Terra
 
Engenharia de Software - Aula1
Engenharia de Software - Aula1Engenharia de Software - Aula1
Engenharia de Software - Aula1Ismar Silveira
 
Estrutura de Dados - Aula 06 - Pilhas Estáticas
Estrutura de Dados - Aula 06 - Pilhas EstáticasEstrutura de Dados - Aula 06 - Pilhas Estáticas
Estrutura de Dados - Aula 06 - Pilhas EstáticasLeinylson Fontinele
 
Arquitetura computadores cor_capa_ficha_20110126.pdf
Arquitetura computadores cor_capa_ficha_20110126.pdfArquitetura computadores cor_capa_ficha_20110126.pdf
Arquitetura computadores cor_capa_ficha_20110126.pdfMatheusRpz
 
Sistemas Operacionais - Aula 05 (Concorrência)
Sistemas Operacionais - Aula 05 (Concorrência)Sistemas Operacionais - Aula 05 (Concorrência)
Sistemas Operacionais - Aula 05 (Concorrência)Leinylson Fontinele
 
Fundamentos de Sistemas de Informacao - Aula 1
Fundamentos de Sistemas de Informacao - Aula 1Fundamentos de Sistemas de Informacao - Aula 1
Fundamentos de Sistemas de Informacao - Aula 1Ismar Silveira
 
Estrutura de Dados - Aula 02 - Estrutura de Dados e TAD
Estrutura de Dados - Aula 02 - Estrutura de Dados e TADEstrutura de Dados - Aula 02 - Estrutura de Dados e TAD
Estrutura de Dados - Aula 02 - Estrutura de Dados e TADLeinylson Fontinele
 
Módulo 5 Arquitetura de Computadores
Módulo 5 Arquitetura de ComputadoresMódulo 5 Arquitetura de Computadores
Módulo 5 Arquitetura de ComputadoresLuis Ferreira
 
Introdução à Computação Aula 04 - INTRODUÇÃO A CIÊNCIA DA COMPUTAÇÃO (Hardwar...
Introdução à Computação Aula 04 - INTRODUÇÃO A CIÊNCIA DA COMPUTAÇÃO (Hardwar...Introdução à Computação Aula 04 - INTRODUÇÃO A CIÊNCIA DA COMPUTAÇÃO (Hardwar...
Introdução à Computação Aula 04 - INTRODUÇÃO A CIÊNCIA DA COMPUTAÇÃO (Hardwar...Leinylson Fontinele
 
Estrutura de Dados - Aula 03 - Ponteiros e Funções
Estrutura de Dados - Aula 03 - Ponteiros e FunçõesEstrutura de Dados - Aula 03 - Ponteiros e Funções
Estrutura de Dados - Aula 03 - Ponteiros e FunçõesLeinylson Fontinele
 

Viewers also liked (20)

E:\Plp 2009 2\Plp 9
E:\Plp 2009 2\Plp 9E:\Plp 2009 2\Plp 9
E:\Plp 2009 2\Plp 9
 
Paradigmas de Linguagens de Programacao- Aula #8
Paradigmas de Linguagens de Programacao- Aula #8Paradigmas de Linguagens de Programacao- Aula #8
Paradigmas de Linguagens de Programacao- Aula #8
 
Paradigmas de linguagens de programacao - aula#10
Paradigmas de linguagens de programacao - aula#10Paradigmas de linguagens de programacao - aula#10
Paradigmas de linguagens de programacao - aula#10
 
Apostila sistema operacional cor capa ficha 2011 02 04
Apostila sistema operacional cor capa ficha 2011 02 04Apostila sistema operacional cor capa ficha 2011 02 04
Apostila sistema operacional cor capa ficha 2011 02 04
 
A Internet das Coisas
A Internet das CoisasA Internet das Coisas
A Internet das Coisas
 
Paradigmas de Linguagens de Programacao - Aula #1
Paradigmas de Linguagens de Programacao - Aula #1Paradigmas de Linguagens de Programacao - Aula #1
Paradigmas de Linguagens de Programacao - Aula #1
 
Introdução à Computação Aula 01 - Apresentação
Introdução à Computação  Aula 01 - ApresentaçãoIntrodução à Computação  Aula 01 - Apresentação
Introdução à Computação Aula 01 - Apresentação
 
Introducao ambiente windows
Introducao ambiente windowsIntroducao ambiente windows
Introducao ambiente windows
 
Paradigmas de Linguagens de programacao - Aula #2
Paradigmas de Linguagens de programacao - Aula #2Paradigmas de Linguagens de programacao - Aula #2
Paradigmas de Linguagens de programacao - Aula #2
 
A Linguagem Lua e suas Aplicações em Jogos
A Linguagem Lua e suas Aplicações em JogosA Linguagem Lua e suas Aplicações em Jogos
A Linguagem Lua e suas Aplicações em Jogos
 
Apostila Algoritmos e Estrutura de Dados (AEDS)
Apostila Algoritmos e Estrutura de Dados (AEDS)Apostila Algoritmos e Estrutura de Dados (AEDS)
Apostila Algoritmos e Estrutura de Dados (AEDS)
 
Engenharia de Software - Aula1
Engenharia de Software - Aula1Engenharia de Software - Aula1
Engenharia de Software - Aula1
 
Estrutura de Dados - Aula 06 - Pilhas Estáticas
Estrutura de Dados - Aula 06 - Pilhas EstáticasEstrutura de Dados - Aula 06 - Pilhas Estáticas
Estrutura de Dados - Aula 06 - Pilhas Estáticas
 
Arquitetura computadores cor_capa_ficha_20110126.pdf
Arquitetura computadores cor_capa_ficha_20110126.pdfArquitetura computadores cor_capa_ficha_20110126.pdf
Arquitetura computadores cor_capa_ficha_20110126.pdf
 
Sistemas Operacionais - Aula 05 (Concorrência)
Sistemas Operacionais - Aula 05 (Concorrência)Sistemas Operacionais - Aula 05 (Concorrência)
Sistemas Operacionais - Aula 05 (Concorrência)
 
Fundamentos de Sistemas de Informacao - Aula 1
Fundamentos de Sistemas de Informacao - Aula 1Fundamentos de Sistemas de Informacao - Aula 1
Fundamentos de Sistemas de Informacao - Aula 1
 
Estrutura de Dados - Aula 02 - Estrutura de Dados e TAD
Estrutura de Dados - Aula 02 - Estrutura de Dados e TADEstrutura de Dados - Aula 02 - Estrutura de Dados e TAD
Estrutura de Dados - Aula 02 - Estrutura de Dados e TAD
 
Módulo 5 Arquitetura de Computadores
Módulo 5 Arquitetura de ComputadoresMódulo 5 Arquitetura de Computadores
Módulo 5 Arquitetura de Computadores
 
Introdução à Computação Aula 04 - INTRODUÇÃO A CIÊNCIA DA COMPUTAÇÃO (Hardwar...
Introdução à Computação Aula 04 - INTRODUÇÃO A CIÊNCIA DA COMPUTAÇÃO (Hardwar...Introdução à Computação Aula 04 - INTRODUÇÃO A CIÊNCIA DA COMPUTAÇÃO (Hardwar...
Introdução à Computação Aula 04 - INTRODUÇÃO A CIÊNCIA DA COMPUTAÇÃO (Hardwar...
 
Estrutura de Dados - Aula 03 - Ponteiros e Funções
Estrutura de Dados - Aula 03 - Ponteiros e FunçõesEstrutura de Dados - Aula 03 - Ponteiros e Funções
Estrutura de Dados - Aula 03 - Ponteiros e Funções
 

More from Ismar Silveira

REA - Recursos Educacionais Abertos
REA - Recursos Educacionais AbertosREA - Recursos Educacionais Abertos
REA - Recursos Educacionais AbertosIsmar Silveira
 
Charla juegos udelar2015_vfinal
Charla juegos udelar2015_vfinalCharla juegos udelar2015_vfinal
Charla juegos udelar2015_vfinalIsmar Silveira
 
Interaccion2014 - Presentation about Open Books, MOOCs and Instructional Design
Interaccion2014 - Presentation about Open Books, MOOCs and Instructional DesignInteraccion2014 - Presentation about Open Books, MOOCs and Instructional Design
Interaccion2014 - Presentation about Open Books, MOOCs and Instructional DesignIsmar Silveira
 
#latinproject @openeducationweek2014 - Methodologies
#latinproject @openeducationweek2014 - Methodologies#latinproject @openeducationweek2014 - Methodologies
#latinproject @openeducationweek2014 - MethodologiesIsmar Silveira
 
MOOC e Educação Aberta - Painel @ #cbie2013
MOOC e Educação Aberta - Painel @ #cbie2013MOOC e Educação Aberta - Painel @ #cbie2013
MOOC e Educação Aberta - Painel @ #cbie2013Ismar Silveira
 
E:\Plp 2009 2\Plp Aula11
E:\Plp 2009 2\Plp Aula11E:\Plp 2009 2\Plp Aula11
E:\Plp 2009 2\Plp Aula11Ismar Silveira
 
Fundamentos de Sistemas de informacao - Aula #16
Fundamentos de Sistemas de informacao - Aula #16Fundamentos de Sistemas de informacao - Aula #16
Fundamentos de Sistemas de informacao - Aula #16Ismar Silveira
 
Um Sistema De Recomendacao para Web 2
Um Sistema De Recomendacao para Web 2Um Sistema De Recomendacao para Web 2
Um Sistema De Recomendacao para Web 2Ismar Silveira
 
Apresentação WAvalia - SBIE 2009
Apresentação WAvalia - SBIE 2009Apresentação WAvalia - SBIE 2009
Apresentação WAvalia - SBIE 2009Ismar Silveira
 
Fundamentos de Sistemas de Informacao - Aula #14 2009_2
Fundamentos de Sistemas de Informacao - Aula #14 2009_2Fundamentos de Sistemas de Informacao - Aula #14 2009_2
Fundamentos de Sistemas de Informacao - Aula #14 2009_2Ismar Silveira
 
Fundamentos de Sistemas de Informacao - Aula 13
Fundamentos de Sistemas de Informacao - Aula 13Fundamentos de Sistemas de Informacao - Aula 13
Fundamentos de Sistemas de Informacao - Aula 13Ismar Silveira
 
Fundamentos de Sistemas de Informacao - Aula 11 2009_2
Fundamentos de Sistemas de Informacao - Aula 11 2009_2Fundamentos de Sistemas de Informacao - Aula 11 2009_2
Fundamentos de Sistemas de Informacao - Aula 11 2009_2Ismar Silveira
 
Fundamentos de Sistemas de Informacao - Aula 12 2009_2
Fundamentos de Sistemas de Informacao - Aula 12 2009_2Fundamentos de Sistemas de Informacao - Aula 12 2009_2
Fundamentos de Sistemas de Informacao - Aula 12 2009_2Ismar Silveira
 
Fundamentos de Sistemas de Informacao - Aula #10_2009_2
Fundamentos de Sistemas de Informacao - Aula #10_2009_2Fundamentos de Sistemas de Informacao - Aula #10_2009_2
Fundamentos de Sistemas de Informacao - Aula #10_2009_2Ismar Silveira
 
Fundamentos de Sistemas de Informacao - Aula #8_2009_2
Fundamentos de Sistemas de Informacao - Aula #8_2009_2Fundamentos de Sistemas de Informacao - Aula #8_2009_2
Fundamentos de Sistemas de Informacao - Aula #8_2009_2Ismar Silveira
 
Fundamentos de Sistemas de Informacao - Aula #8_2009_2
Fundamentos de Sistemas de Informacao - Aula #8_2009_2Fundamentos de Sistemas de Informacao - Aula #8_2009_2
Fundamentos de Sistemas de Informacao - Aula #8_2009_2Ismar Silveira
 
Fundamentos de Sistemas de Informacao - Aula #9_2009_2
Fundamentos de Sistemas de Informacao - Aula #9_2009_2Fundamentos de Sistemas de Informacao - Aula #9_2009_2
Fundamentos de Sistemas de Informacao - Aula #9_2009_2Ismar Silveira
 

More from Ismar Silveira (20)

REA - Recursos Educacionais Abertos
REA - Recursos Educacionais AbertosREA - Recursos Educacionais Abertos
REA - Recursos Educacionais Abertos
 
Charla juegos udelar2015_vfinal
Charla juegos udelar2015_vfinalCharla juegos udelar2015_vfinal
Charla juegos udelar2015_vfinal
 
Interaccion2014 - Presentation about Open Books, MOOCs and Instructional Design
Interaccion2014 - Presentation about Open Books, MOOCs and Instructional DesignInteraccion2014 - Presentation about Open Books, MOOCs and Instructional Design
Interaccion2014 - Presentation about Open Books, MOOCs and Instructional Design
 
#latinproject @openeducationweek2014 - Methodologies
#latinproject @openeducationweek2014 - Methodologies#latinproject @openeducationweek2014 - Methodologies
#latinproject @openeducationweek2014 - Methodologies
 
MOOC e Educação Aberta - Painel @ #cbie2013
MOOC e Educação Aberta - Painel @ #cbie2013MOOC e Educação Aberta - Painel @ #cbie2013
MOOC e Educação Aberta - Painel @ #cbie2013
 
Fundcompsis 1.1
Fundcompsis 1.1Fundcompsis 1.1
Fundcompsis 1.1
 
Ismar webinar-udelar
Ismar webinar-udelarIsmar webinar-udelar
Ismar webinar-udelar
 
wei2010
wei2010wei2010
wei2010
 
E:\Plp 2009 2\Plp Aula11
E:\Plp 2009 2\Plp Aula11E:\Plp 2009 2\Plp Aula11
E:\Plp 2009 2\Plp Aula11
 
Fundamentos de Sistemas de informacao - Aula #16
Fundamentos de Sistemas de informacao - Aula #16Fundamentos de Sistemas de informacao - Aula #16
Fundamentos de Sistemas de informacao - Aula #16
 
Um Sistema De Recomendacao para Web 2
Um Sistema De Recomendacao para Web 2Um Sistema De Recomendacao para Web 2
Um Sistema De Recomendacao para Web 2
 
Apresentação WAvalia - SBIE 2009
Apresentação WAvalia - SBIE 2009Apresentação WAvalia - SBIE 2009
Apresentação WAvalia - SBIE 2009
 
Fundamentos de Sistemas de Informacao - Aula #14 2009_2
Fundamentos de Sistemas de Informacao - Aula #14 2009_2Fundamentos de Sistemas de Informacao - Aula #14 2009_2
Fundamentos de Sistemas de Informacao - Aula #14 2009_2
 
Fundamentos de Sistemas de Informacao - Aula 13
Fundamentos de Sistemas de Informacao - Aula 13Fundamentos de Sistemas de Informacao - Aula 13
Fundamentos de Sistemas de Informacao - Aula 13
 
Fundamentos de Sistemas de Informacao - Aula 11 2009_2
Fundamentos de Sistemas de Informacao - Aula 11 2009_2Fundamentos de Sistemas de Informacao - Aula 11 2009_2
Fundamentos de Sistemas de Informacao - Aula 11 2009_2
 
Fundamentos de Sistemas de Informacao - Aula 12 2009_2
Fundamentos de Sistemas de Informacao - Aula 12 2009_2Fundamentos de Sistemas de Informacao - Aula 12 2009_2
Fundamentos de Sistemas de Informacao - Aula 12 2009_2
 
Fundamentos de Sistemas de Informacao - Aula #10_2009_2
Fundamentos de Sistemas de Informacao - Aula #10_2009_2Fundamentos de Sistemas de Informacao - Aula #10_2009_2
Fundamentos de Sistemas de Informacao - Aula #10_2009_2
 
Fundamentos de Sistemas de Informacao - Aula #8_2009_2
Fundamentos de Sistemas de Informacao - Aula #8_2009_2Fundamentos de Sistemas de Informacao - Aula #8_2009_2
Fundamentos de Sistemas de Informacao - Aula #8_2009_2
 
Fundamentos de Sistemas de Informacao - Aula #8_2009_2
Fundamentos de Sistemas de Informacao - Aula #8_2009_2Fundamentos de Sistemas de Informacao - Aula #8_2009_2
Fundamentos de Sistemas de Informacao - Aula #8_2009_2
 
Fundamentos de Sistemas de Informacao - Aula #9_2009_2
Fundamentos de Sistemas de Informacao - Aula #9_2009_2Fundamentos de Sistemas de Informacao - Aula #9_2009_2
Fundamentos de Sistemas de Informacao - Aula #9_2009_2
 

Recently uploaded

General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxNikitaBankoti2
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 

Recently uploaded (20)

General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 

Paradigmas de Linguagens de Programacao - Aula #7

  • 1. Paradigmas de Linguagens de Programação Paradigma Orientado a Objetos Aula #7 (CopyLeft)2009 - Ismar Frango ismar@mackenzie.br
  • 2. “ There are only two kinds of languages: the ones people complain about and the ones nobody uses.” Bjarne Stroustrup Binding em LOO
  • 3.  
  • 4.  
  • 6.  
  • 8.  
  • 9.  
  • 11. ?
  • 12. Asteroid SpaceShip Thing Dispatching em LOO
  • 13. abstract class Thing { public abstract void collideWith ( Thing other); } class Asteroid extends Thing { public void collideWith ( Thing other) { if (other instanceof Asteroid ) { // handle Asteroid-Asteroid collision } else if (other instanceof Spaceship ) { // handle Asteroid-Spaceship collision } } } class Spaceship extends Thing { public void collideWith ( Thing other) { if (other instanceof Asteroid ) { // handle Spaceship-Asteroid collision } else if (other instanceof Spaceship ) { // handle Spaceship-Spaceship collision } } }
  • 14. abstract class Thing { public abstract void collideWith ( Thing other); } class Asteroid extends Thing { public void collideWith ( Asteroid other) { System.out.println(&quot;handle Asteroid-Asteroid collision&quot;); } public void collideWith ( Spaceship s) { System.out.println(&quot;handle Asteroid-Spaceship collision&quot;); } } class Spaceship extends Thing { public void collideWith ( Asteroid a) { System.out.println(&quot;handle Spaceship-Asteroid collision&quot;); } public void collideWith ( Spaceship other) { System.out.println(&quot;handle Spaceship-Spaceship collision&quot;); } } 
  • 15. abstract class Thing { public abstract void collideWith ( Thing other); } class Asteroid extends Thing { public void collideWith ( Thing other) {} public void collideWith ( Asteroid other) { System.out.println(&quot;handle Asteroid-Asteroid collision&quot;); } public void collideWith ( Spaceship s) { System.out.println(&quot;handle Asteroid-Spaceship collision&quot;); } } class Spaceship extends Thing { public void collideWith ( Thing other) {} public void collideWith ( Asteroid a) { System.out.println(&quot;handle Spaceship-Asteroid collision&quot;); } public void collideWith ( Spaceship other) { System.out.println(&quot;handle Spaceship-Spaceship collision&quot;); } } 
  • 16. Asteroid ExplodingAsteroid SpaceShip GiantSpaceShip Thing
  • 17. class SpaceShip {}; class GiantSpaceShip : public SpaceShip {}; class Asteroid { public : virtual void CollideWith (SpaceShip&) { cout << &quot;Asteroid hit a SpaceShip&quot; << endl; } virtual void CollideWith (GiantSpaceShip&) { cout << &quot;Asteroid hit a GiantSpaceShip&quot; << endl; } }; class ExplodingAsteroid : public Asteroid { public : virtual void CollideWith (SpaceShip&) { cout << &quot;ExplodingAsteroid hit a SpaceShip&quot; << endl; } virtual void CollideWith (GiantSpaceShip&) { cout << &quot;ExplodingAsteroid hit a GiantSpaceShip&quot; << endl; } };
  • 18. class SpaceShip {}; class GiantSpaceShip : public SpaceShip {}; class Asteroid { public : virtual void CollideWith (SpaceShip&) { cout << &quot;Asteroid hit a SpaceShip&quot; << endl; } virtual void CollideWith (GiantSpaceShip&) { cout << &quot;Asteroid hit a GiantSpaceShip&quot; << endl; } }; class ExplodingAsteroid : public Asteroid { public : virtual void CollideWith (SpaceShip&) { cout << &quot;ExplodingAsteroid hit a SpaceShip&quot; << endl; } virtual void CollideWith (GiantSpaceShip&) { cout << &quot;ExplodingAsteroid hit a GiantSpaceShip&quot; << endl; } }; Asteroid theAsteroid; SpaceShip theSpaceShip; GiantSpaceShip theGiantSpaceShip; theAsteroid . CollideWith (theSpaceShip); theAsteroid . CollideWith (theGiantSpaceShip); Asteroid * theAsteroidReference = new ExplodingAsteroid (); theAsteroidReference -> CollideWith (theSpaceShip); theAsteroidReference -> CollideWith (theGiantSpaceShip); SpaceShip & theSpaceShipReference = theGiantSpaceShip; theAsteroid . CollideWith (theSpaceShipReference); theAsteroidReference -> CollideWith (theSpaceShipReference);
  • 19. class SpaceShip { virtual void CollideWith ( Asteroid & inAsteroid) { inAsteroid. CollideWith (* this ); } }; class GiantSpaceShip : public SpaceShip {}; Asteroid hit a SpaceShip ExplodingAsteroid hit a SpaceShip SpaceShip & theSpaceShipReference = theGiantSpaceShip; Asteroid & theAsteroidReference = theExplodingAsteroid; theSpaceShipReference. CollideWith (theAsteroid); theSpaceShipReference. CollideWith (theAsteroidReference); class SpaceShip { virtual void CollideWith ( Asteroid & inAsteroid) { inAsteroid. CollideWith (* this ); } }; class GiantSpaceShip : public SpaceShip { virtual void CollideWith ( Asteroid & inAsteroid) { inAsteroid. CollideWith (* this ); } }; Asteroid hit a GiantSpaceShip ExplodingAsteroid hit a GiantSpaceShip