CSDN博客

img IWillSaveGod

The Problems in OO Typing(Not Finished)

发表于2004/6/23 20:18:00  669人阅读

 
Typing of
? Encapsulation (Solved: existential types [Girard 71])
?  Inheritance (Partially solved)
?  Polymorphism (Open issue)
 
 
 
 
Typing Inheritance
1.
Covariant Typing
Animal {
   Shit eats(Food)
}
Cow extends Animal {
  CowShit eats(Grass)
}
Problem: Not type sound
Animal a = new Cow();
Food f = new Hamburger();
a.eat(f); //Food poisoning
 
2.
 
Contravariant Typing
Animal {
   Shit eats(Grass)
}
Cow extends Animal {
  CowShit eats(Food)
}
Problem:
Sound but not flexible
3.
 
Novariant Typing
Animal {
   Shit eats(Food)
}
Cow extends Animal {
  Shit eats(Food)
}
Problem:
Worst of both worlds.
 
 
0 0

相关博文

我的热门文章

img
取 消
img