The Concept of Subtyping Explained from a Type System Perspective
The Concept of Subtyping Explained from a Type System Perspective
Andr´ e Gasser
HSR Hochschule f¨ ur Technik Rapperswil
June 10, 2015
1 / 27
The Concept of Subtyping Explained from a Type System Perspective - - PowerPoint PPT Presentation
The Concept of Subtyping Explained from a Type System Perspective The Concept of Subtyping Explained from a Type System Perspective Andr e Gasser HSR Hochschule f ur Technik Rapperswil June 10, 2015 1 / 27 The Concept of Subtyping
The Concept of Subtyping Explained from a Type System Perspective
HSR Hochschule f¨ ur Technik Rapperswil
1 / 27
The Concept of Subtyping Explained from a Type System Perspective
1 Introduction 2 Subtyping 3 Subtyping in C# 4 Conclusion
2 / 27
The Concept of Subtyping Explained from a Type System Perspective Introduction
1 Introduction 2 Subtyping 3 Subtyping in C# 4 Conclusion
3 / 27
The Concept of Subtyping Explained from a Type System Perspective Introduction
4 / 27
The Concept of Subtyping Explained from a Type System Perspective Introduction
5 / 27
The Concept of Subtyping Explained from a Type System Perspective Subtyping
1 Introduction 2 Subtyping 3 Subtyping in C# 4 Conclusion
6 / 27
The Concept of Subtyping Explained from a Type System Perspective Subtyping
7 / 27
The Concept of Subtyping Explained from a Type System Perspective Subtyping
8 / 27
The Concept of Subtyping Explained from a Type System Perspective Subtyping
9 / 27
The Concept of Subtyping Explained from a Type System Perspective Subtyping
10 / 27
The Concept of Subtyping Explained from a Type System Perspective Subtyping
11 / 27
The Concept of Subtyping Explained from a Type System Perspective Subtyping
12 / 27
The Concept of Subtyping Explained from a Type System Perspective Subtyping
1 c l a s s Dog { } 2 c l a s s T e r r i e r : Dog { } 3 4 abstract c l a s s Enclosure 5 { 6 public abstract Dog Get ( ) ; 7 } 8 9 c l a s s DogHouse : Enclosure 10 { 11 public
T e r r i e r Get () 12 { 13 . . . 14 } 15 }
13 / 27
The Concept of Subtyping Explained from a Type System Perspective Subtyping
14 / 27
The Concept of Subtyping Explained from a Type System Perspective Subtyping
15 / 27
The Concept of Subtyping Explained from a Type System Perspective Subtyping
1 Point { x : int , y : i n t } 2 Point3D { x : int , y : int , z : i n t }
16 / 27
The Concept of Subtyping Explained from a Type System Perspective Subtyping
17 / 27
The Concept of Subtyping Explained from a Type System Perspective Subtyping
1 c l a s s Fish { } 2 c l a s s GoldFish : Fish { } 3 4 Aquarium 5 { 6 volume : int , 7 f i s h : Fish 8 } 9 10 GoldFishAquarium 11 { 12 volume : int , 13 f i s h : GoldFish 14 }
18 / 27
The Concept of Subtyping Explained from a Type System Perspective Subtyping
19 / 27
The Concept of Subtyping Explained from a Type System Perspective Subtyping in C#
1 Introduction 2 Subtyping 3 Subtyping in C# 4 Conclusion
20 / 27
The Concept of Subtyping Explained from a Type System Perspective Subtyping in C#
21 / 27
The Concept of Subtyping Explained from a Type System Perspective Subtyping in C#
22 / 27
The Concept of Subtyping Explained from a Type System Perspective Subtyping in C#
1 c l a s s Dog { } 2 c l a s s T e r r i e r : Dog { } 3 c l a s s B o r d e r C o l l i e : Dog { } 4 5 // Dog [ ] can contain 6 // Dogs ,
s u b c l a s s e s
Dogs 7 Dog [ ] dogs = new Dog [ 3 ] ; 8 dogs [ 0 ] = new Dog( ” L a s s i e ” ) ; 9 dogs [ 1 ] = new T e r r i e r ( ” Jack ” ) ; 10 dogs [ 2 ] = new B o r d e r C o l l i e ( ” Kirby ” ) ;
23 / 27
The Concept of Subtyping Explained from a Type System Perspective Subtyping in C#
1 c l a s s Dog { } 2 c l a s s T e r r i e r : Dog { } 3 c l a s s B o r d e r C o l l i e : Dog { } 4 5 Dog [ ] dogs = new T e r r i e r [ 3 ] ; 6 7 // This i s OK 8 dogs [ 0 ] = new T e r r i e r ( ” Jack ” ) ; 9 10 // This l e a d s to a runtime e r r o r 11 dogs [ 1 ] = new B o r d e r C o l l i e ( ” Kirby ” ) ;
24 / 27
The Concept of Subtyping Explained from a Type System Perspective Conclusion
1 Introduction 2 Subtyping 3 Subtyping in C# 4 Conclusion
25 / 27
The Concept of Subtyping Explained from a Type System Perspective Conclusion
26 / 27
The Concept of Subtyping Explained from a Type System Perspective Conclusion
27 / 27