SlideShare ist ein Scribd-Unternehmen logo
1 von 33
Downloaden Sie, um offline zu lesen
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
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
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
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
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
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 November 7, 2010 5 / 14
Issues
Implementation (flexible and efficient).
Type safety.
Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 5 / 14
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
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
The Strategy Pattern
Implementation: indirect pointers.
Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 6 / 14
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
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
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
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
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
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
Gilgul
Implementation: indirect pointers.
Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 8 / 14
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
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
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
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
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
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
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
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
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
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
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
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
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
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

Weitere ähnliche Inhalte

Andere mochten auch

Andere mochten auch (17)

Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Functional Concepts
Functional ConceptsFunctional Concepts
Functional Concepts
 
Flow Control
Flow ControlFlow Control
Flow Control
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritance
 
Subtyping
SubtypingSubtyping
Subtyping
 
Prototype Languages
Prototype LanguagesPrototype Languages
Prototype Languages
 
Multiple Dispatch
Multiple DispatchMultiple Dispatch
Multiple Dispatch
 
Garbage Collection
Garbage CollectionGarbage Collection
Garbage Collection
 
T+L Copy2
T+L Copy2T+L Copy2
T+L Copy2
 
Every Consumer is a Business user is a Consumer
Every Consumer is a Business user is a ConsumerEvery Consumer is a Business user is a Consumer
Every Consumer is a Business user is a Consumer
 
Inheritance
InheritanceInheritance
Inheritance
 
What Would You Say
What Would You SayWhat Would You Say
What Would You Say
 
Type Systems
Type SystemsType Systems
Type Systems
 
M2MSys ITIL Executive Summary
M2MSys ITIL Executive SummaryM2MSys ITIL Executive Summary
M2MSys ITIL Executive Summary
 
What Would You Say
What Would You SayWhat Would You Say
What Would You Say
 
Setup1
Setup1Setup1
Setup1
 
België Nederland
België NederlandBelgië Nederland
België Nederland
 

Ähnlich wie Reclassification

Object? You Keep Using that Word
Object? You Keep Using that WordObject? You Keep Using that Word
Object? You Keep Using that WordKevlin Henney
 
Ontology Building and its Application using Hozo
Ontology Building and its Application using HozoOntology Building and its Application using Hozo
Ontology Building and its Application using HozoKouji Kozaki
 
Knowledge extraction in Web media: at the frontier of NLP, Machine Learning a...
Knowledge extraction in Web media: at the frontier of NLP, Machine Learning a...Knowledge extraction in Web media: at the frontier of NLP, Machine Learning a...
Knowledge extraction in Web media: at the frontier of NLP, Machine Learning a...Julien PLU
 
MLGrafViz: multilingual ontology visualization plug-in for Protégé
MLGrafViz: multilingual ontology visualization plug-in for ProtégéMLGrafViz: multilingual ontology visualization plug-in for Protégé
MLGrafViz: multilingual ontology visualization plug-in for ProtégéCSITiaesprime
 
TMPA-2017: Layered Layouts for Software Systems Visualization
TMPA-2017: Layered Layouts for Software Systems VisualizationTMPA-2017: Layered Layouts for Software Systems Visualization
TMPA-2017: Layered Layouts for Software Systems VisualizationIosif Itkin
 
Automated Identification of Framing by Word Choice and Labeling to Reveal Med...
Automated Identification of Framing by Word Choice and Labeling to Reveal Med...Automated Identification of Framing by Word Choice and Labeling to Reveal Med...
Automated Identification of Framing by Word Choice and Labeling to Reveal Med...Anastasia Zhukova
 
JavaScript for ABAP Programmers - 6/7 Inheritance
JavaScript for ABAP Programmers - 6/7 InheritanceJavaScript for ABAP Programmers - 6/7 Inheritance
JavaScript for ABAP Programmers - 6/7 InheritanceChris Whealy
 

Ähnlich wie Reclassification (8)

Object? You Keep Using that Word
Object? You Keep Using that WordObject? You Keep Using that Word
Object? You Keep Using that Word
 
Ontology Building and its Application using Hozo
Ontology Building and its Application using HozoOntology Building and its Application using Hozo
Ontology Building and its Application using Hozo
 
Knowledge extraction in Web media: at the frontier of NLP, Machine Learning a...
Knowledge extraction in Web media: at the frontier of NLP, Machine Learning a...Knowledge extraction in Web media: at the frontier of NLP, Machine Learning a...
Knowledge extraction in Web media: at the frontier of NLP, Machine Learning a...
 
MLGrafViz: multilingual ontology visualization plug-in for Protégé
MLGrafViz: multilingual ontology visualization plug-in for ProtégéMLGrafViz: multilingual ontology visualization plug-in for Protégé
MLGrafViz: multilingual ontology visualization plug-in for Protégé
 
TMPA-2017: Layered Layouts for Software Systems Visualization
TMPA-2017: Layered Layouts for Software Systems VisualizationTMPA-2017: Layered Layouts for Software Systems Visualization
TMPA-2017: Layered Layouts for Software Systems Visualization
 
Automated Identification of Framing by Word Choice and Labeling to Reveal Med...
Automated Identification of Framing by Word Choice and Labeling to Reveal Med...Automated Identification of Framing by Word Choice and Labeling to Reveal Med...
Automated Identification of Framing by Word Choice and Labeling to Reveal Med...
 
JavaScript for ABAP Programmers - 6/7 Inheritance
JavaScript for ABAP Programmers - 6/7 InheritanceJavaScript for ABAP Programmers - 6/7 Inheritance
JavaScript for ABAP Programmers - 6/7 Inheritance
 
Ws2001 sessione8 cibella_tuoto
Ws2001 sessione8 cibella_tuotoWs2001 sessione8 cibella_tuoto
Ws2001 sessione8 cibella_tuoto
 

Kürzlich hochgeladen

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
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 

Kürzlich hochgeladen (20)

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Ữ Â...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 

Reclassification

  • 1.
  • 2. 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
  • 3. 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
  • 4. 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
  • 5. 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
  • 6. 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
  • 7. Issues Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 5 / 14
  • 8. Issues Implementation (flexible and efficient). Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 5 / 14
  • 9. Issues Implementation (flexible and efficient). Type safety. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 5 / 14
  • 10. 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
  • 11. 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
  • 12. The Strategy Pattern Implementation: indirect pointers. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 6 / 14
  • 13. 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
  • 14. 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
  • 15. 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
  • 16. 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
  • 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. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 7 / 14
  • 18. 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
  • 19. Gilgul Implementation: indirect pointers. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 8 / 14
  • 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. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 8 / 14
  • 21. 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
  • 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. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 9 / 14
  • 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. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 9 / 14
  • 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. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 9 / 14
  • 25. 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
  • 26. 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
  • 27. 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
  • 28. 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
  • 29. 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
  • 30. 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
  • 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. Michal P´ıˇse (CTU in Prague) Object Programming Lect. 7: Reclassification November 7, 2010 13 / 14
  • 32. 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
  • 33. 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