Scenario
In a first person shooter:
enemies tend to change their behavior when they become aware of the
player’s presence (...
Problem
How to represent enemies?
Single class with a typecode—clumsy.
Michal P´ıˇse (CTU in Prague) Object Programming Le...
Problem
How to represent enemies?
Single class with a typecode—clumsy.
Multiple classes, events and pointer redirection—to...
Problem
How to represent enemies?
Single class with a typecode—clumsy.
Multiple classes, events and pointer redirection—to...
Reclassification
Change of a class of an object during its lifetime.
Not implemented in current industrial programming lang...
Issues
Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 5 / 14
Issues
Implementation (flexible and efficient).
Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification Nov...
Issues
Implementation (flexible and efficient).
Type safety.
Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclas...
Issues
Implementation (flexible and efficient).
Type safety.
Halfway executed methods invoked on the reclassified object.
Mich...
Issues
Implementation (flexible and efficient).
Type safety.
Halfway executed methods invoked on the reclassified object.
Over...
The Strategy Pattern
Implementation: indirect pointers.
Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassi...
The Strategy Pattern
Implementation: indirect pointers.
Envelope defines its own type.
Michal P´ıˇse (CTU in Prague) Object...
The Strategy Pattern
Implementation: indirect pointers.
Envelope defines its own type.
Halfway executed methods continue th...
Smalltalk’s become:
Implementation: redirect pointer referencing class object.
Michal P´ıˇse (CTU in Prague) Object Progra...
Smalltalk’s become:
Implementation: redirect pointer referencing class object.
No type safety (as in the rest of the langu...
Smalltalk’s become:
Implementation: redirect pointer referencing class object.
No type safety (as in the rest of the langu...
Smalltalk’s become:
Implementation: redirect pointer referencing class object.
No type safety (as in the rest of the langu...
Gilgul
Implementation: indirect pointers.
Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification Novemb...
Gilgul
Implementation: indirect pointers.
Optionally, an exception is raised when reclassifying an object with
methods on ...
Gilgul
Implementation: indirect pointers.
Optionally, an exception is raised when reclassifying an object with
methods on ...
Fickle
Three types of classes: normal, root and state.
Root classes can only inherit from normal classes.
Root classes can...
Fickle
Three types of classes: normal, root and state.
Root classes can only inherit from normal classes.
Root classes can...
Fickle
Three types of classes: normal, root and state.
Root classes can only inherit from normal classes.
Root classes can...
Fickle
Three types of classes: normal, root and state.
Root classes can only inherit from normal classes.
Root classes can...
Example
root class Player {
bool brave;
abstract Weapon kissed(){Player}
}
state class Frog extends Player {
Vocal pouch;
...
Example (II)
bool play(Player p, Frog f){Player} {
f.pouch; // correct
p.kissed();
f.pouch; // incorrect
p.brave; //correc...
Predicate Classes
Combination of multiple dispatch with automatic reclassification.
An object is reclassified once a predica...
Typing Issues of Predicate Classes
The system uses multimethods.
Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7:...
Typing Issues of Predicate Classes
The system uses multimethods.
It guarantees no method invocation is ambiguous.
Michal P...
Typing Issues of Predicate Classes
The system uses multimethods.
It guarantees no method invocation is ambiguous.
Compiler...
Typing Issues of Predicate Classes
The system uses multimethods.
It guarantees no method invocation is ambiguous.
Compiler...
See
Sophia Drossopoulou, Ferruccio Damiani, Mariangiola Dezani-Ciancaglini,
and Paola Giannini. More Dynamic Object Reclas...
Reclassification
Upcoming SlideShare
Loading in...5
×

Reclassification

381

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
381
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
34
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Reclassification"

  1. 1. Scenario In a first person shooter: enemies tend to change their behavior when they become aware of the player’s presence (and then again when they empty their magazines), under the hood, they are typically represented by objects and references pointing at them are often spread across the whole memory. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 2 / 14
  2. 2. Problem How to represent enemies? Single class with a typecode—clumsy. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 3 / 14
  3. 3. Problem How to represent enemies? Single class with a typecode—clumsy. Multiple classes, events and pointer redirection—too complicated, not feasible. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 3 / 14
  4. 4. Problem How to represent enemies? Single class with a typecode—clumsy. Multiple classes, events and pointer redirection—too complicated, not feasible. The strategy pattern. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 3 / 14
  5. 5. Reclassification Change of a class of an object during its lifetime. Not implemented in current industrial programming languages. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 4 / 14
  6. 6. Issues Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 5 / 14
  7. 7. Issues Implementation (flexible and efficient). Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 5 / 14
  8. 8. Issues Implementation (flexible and efficient). Type safety. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 5 / 14
  9. 9. Issues Implementation (flexible and efficient). Type safety. Halfway executed methods invoked on the reclassified object. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 5 / 14
  10. 10. Issues Implementation (flexible and efficient). Type safety. Halfway executed methods invoked on the reclassified object. Overall design: cleanliness, consistency and interaction with other features of the language. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 5 / 14
  11. 11. The Strategy Pattern Implementation: indirect pointers. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 6 / 14
  12. 12. The Strategy Pattern Implementation: indirect pointers. Envelope defines its own type. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 6 / 14
  13. 13. The Strategy Pattern Implementation: indirect pointers. Envelope defines its own type. Halfway executed methods continue their execution on the original object—they are not aware of the replacement. However, they may damage the context. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 6 / 14
  14. 14. Smalltalk’s become: Implementation: redirect pointer referencing class object. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 7 / 14
  15. 15. Smalltalk’s become: Implementation: redirect pointer referencing class object. No type safety (as in the rest of the language). Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 7 / 14
  16. 16. Smalltalk’s become: Implementation: redirect pointer referencing class object. No type safety (as in the rest of the language). Halfway executed methods continue their execution—it is up to the programmer to make sure they cause no harm. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 7 / 14
  17. 17. Smalltalk’s become: Implementation: redirect pointer referencing class object. No type safety (as in the rest of the language). Halfway executed methods continue their execution—it is up to the programmer to make sure they cause no harm. Overall design in sync with the rest of the language. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 7 / 14
  18. 18. Gilgul Implementation: indirect pointers. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 8 / 14
  19. 19. Gilgul Implementation: indirect pointers. Optionally, an exception is raised when reclassifying an object with methods on the stack. When all methods invoked on that objects are unwound, the last one is restarted. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 8 / 14
  20. 20. Gilgul Implementation: indirect pointers. Optionally, an exception is raised when reclassifying an object with methods on the stack. When all methods invoked on that objects are unwound, the last one is restarted. Reclassification is a global issue—indirectly or directly reclassifying methods should either be side-effect free or abortable/restartable. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 8 / 14
  21. 21. Fickle Three types of classes: normal, root and state. Root classes can only inherit from normal classes. Root classes can only be parents to state classes. State classes can only inherit from root classes or state classes. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 9 / 14
  22. 22. Fickle Three types of classes: normal, root and state. Root classes can only inherit from normal classes. Root classes can only be parents to state classes. State classes can only inherit from root classes or state classes. State classes can not be used as field types. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 9 / 14
  23. 23. Fickle Three types of classes: normal, root and state. Root classes can only inherit from normal classes. Root classes can only be parents to state classes. State classes can only inherit from root classes or state classes. State classes can not be used as field types. Methods have to declare root classes of directly or indirectly reclassified objects. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 9 / 14
  24. 24. Fickle Three types of classes: normal, root and state. Root classes can only inherit from normal classes. Root classes can only be parents to state classes. State classes can only inherit from root classes or state classes. State classes can not be used as field types. Methods have to declare root classes of directly or indirectly reclassified objects. Static types of variables change conservatively to accommodate for the effects of reclassification. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 9 / 14
  25. 25. Example root class Player { bool brave; abstract Weapon kissed(){Player} } state class Frog extends Player { Vocal pouch; Weapon kissed(){Player}{this⇓Prince; sword = new Weapon} } state class Prince extends Player { Weapon sword; Weapon kissed(){Player}{sword} } Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 10 / 14
  26. 26. Example (II) bool play(Player p, Frog f){Player} { f.pouch; // correct p.kissed(); f.pouch; // incorrect p.brave; //correct } Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 11 / 14
  27. 27. Predicate Classes Combination of multiple dispatch with automatic reclassification. An object is reclassified once a predicate is fulfilled. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 12 / 14
  28. 28. Typing Issues of Predicate Classes The system uses multimethods. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 13 / 14
  29. 29. Typing Issues of Predicate Classes The system uses multimethods. It guarantees no method invocation is ambiguous. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 13 / 14
  30. 30. Typing Issues of Predicate Classes The system uses multimethods. It guarantees no method invocation is ambiguous. Compiler raises an error if it can not deduce no ambiguity can occur. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 13 / 14
  31. 31. Typing Issues of Predicate Classes The system uses multimethods. It guarantees no method invocation is ambiguous. Compiler raises an error if it can not deduce no ambiguity can occur. A programmer may provide an additional information which helps to dispel suspicions of ambiguity using disjoint and cover primitives. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 13 / 14
  32. 32. See Sophia Drossopoulou, Ferruccio Damiani, Mariangiola Dezani-Ciancaglini, and Paola Giannini. More Dynamic Object Reclassification: FickleII. ACM Transactions on Programming Languages and Systems 24, 2 (March 2002). 153–191. http://doi.acm.org/10.1145/514952.514955 Craig Chambers. Predicate Classes. Proceedings of the 7th European Conference on Object-Oriented Programming (ECOOP ’93), Oscar Nierstrasz (Ed.). Springer-Verlag, London, UK. 268–296. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 14 / 14
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×