• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Paradigmas de Linguagens de Programacao - Aula #7
 

Paradigmas de Linguagens de Programacao - Aula #7

on

  • 1,661 views

Paradigmas de Linguagens de Programacao

Paradigmas de Linguagens de Programacao
Aula #7
Prof. Ismar Frango

Statistics

Views

Total Views
1,661
Views on SlideShare
1,630
Embed Views
31

Actions

Likes
2
Downloads
92
Comments
0

1 Embed 31

http://www.slideshare.net 31

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Paradigmas de Linguagens de Programacao - Aula #7 Paradigmas de Linguagens de Programacao - Aula #7 Presentation Transcript

    • Paradigmas de Linguagens de Programação Paradigma Orientado a Objetos Aula #8 (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