Presentation is loading. Please wait.

Presentation is loading. Please wait.

Polymorphism Chapter six of: Szyperski, Clemens et al. Component Software - Beyond Object-Oriented Programming. Second Edition.

Similar presentations


Presentation on theme: "Polymorphism Chapter six of: Szyperski, Clemens et al. Component Software - Beyond Object-Oriented Programming. Second Edition."— Presentation transcript:

1 Polymorphism Chapter six of: Szyperski, Clemens et al. Component Software - Beyond Object-Oriented Programming. Second Edition

2 Schedule  Concept  Substitutability  Types, subtypes, and type checking  Object languages and types  Types, interfaces, and components  The paradigm of independent extensibility  Safety by construction

3 Schedule  Module safety  Safety, security, trust

4 Concept “Polymorphism is the ability of something to appear in multiple forms, depending on context, and the ability of different things to appear the same in a certain context”

5 Substitutability  What a interface should require? What is essential for the service  A Client may establish more than is required by the precondition  A Provider may establish more than is required by the postcondition

6 Interface TextModel{ int max();//maximum length this text can have int length();//current length char read(int pos);//character at position pos void write(int pos, char ch);//insert character ch at position pos //[len: int; txt : array of char Pre len:=this.length();(all i:0  i<len: txt[i] := this.read(i)); len<this.max() and 0  pos  len Post this.length() = len + 1 and (all i:0  i<pos: this.read(i) = txt[i]) and this.read(pos) = ch and (all i:pos<i<this.length(): this.read(i) = txt[i-1]) //] }

7 Class GreatTextModel implements TextModel{... void write(int pos, char ch){ //[len: int; txt : array of char Pre len := this.length(); (all i:0  i<len: txt[i] := this.read(i)); len<this.max() and 0  pos < this.max() Post this.length() = max(len, pos) + 1 and (all i: 0  i < min(pos,len) : this.read(i) = txt[i]) and this.read(pos) = ch and (all i: pos < i  len: this.read(i) = txt[i-1]) and (all i: len < i < pos: this.read(i) = “ ”) //]... }.... }

8 Substitutability Clients InterfaceProviders Calls Results

9 Types, subtypes, and type checking  Chekings  Memory errors  Types: sets of all values of related semantics  Type Contexts  Types in Preconditions and Postconditions  Ways to form subtypes

10 Interface View{ void close(); void restore(int left, int top, int right, int bottom); } Interface TextView extends View{ int caretPos(); void setCaretPos(int pos); } Interface Graphics extends View{ int cursorX(); int cursorY(); void setCursorXY(int x, int y); }

11 Subtypes  Subcontract  Covariance and Contravariance Function F Function G

12 Object languages and types  No Explicit type system Smalltalk, Strongtalk Runtime checking  Explicit type system Java Compiler-time checking Narrowing type casts

13 Other forms of polymorphism  Overloading  Parametric polymorphism  Bounded polymorphism

14 Types, interfaces, and components  Interfaces  Type inference  Structural subtyping  Category Microsoft´s COM IDL

15 The paradigm of independent extensibility  A system is independently extensibility if it is extensible and if independently developed extensions can be combined (Szyperski,1996)  Applications and SOs are fragmented  Flexibility X Performance and robustness

16 Safety by construction  Viability of components  Examples: Java Component Pascal.Net

17 Module safety  A component has to specify explicitly which services it needs to access  Module safety is not simple  Reflection service  Metaprograming

18 Safety, security, trust  Type safety, module safety, and absence of memory errors may be not enough  Formal proofs  Sociological process

19 Extensions  Orthogonal  Bottleneck interfaces  Singleton  Parallel  Recursive

20 Evolution x immutability of interfaces and contracts  Interface  Specification


Download ppt "Polymorphism Chapter six of: Szyperski, Clemens et al. Component Software - Beyond Object-Oriented Programming. Second Edition."

Similar presentations


Ads by Google