Presentation is loading. Please wait.

Presentation is loading. Please wait.

Formal Specification of Java Interfaces

Similar presentations


Presentation on theme: "Formal Specification of Java Interfaces"— Presentation transcript:

1 Formal Specification of Java Interfaces
Jason Hallstrom and Murali Sitaraman Clemson University

2 Basics An interface Describes what classes or components do
Does not describe how they should do it Is a contract between component users (clients) and developers (implementers) If the users satisfy the requirements for using the component, the component will provide guarantees

3 Principles of Interface Design
Information hiding Hide details unnecessary to use the component Abstraction Provide a “cover story” or explanation in user-oriented terms so they can understand the interface

4 Contract specifications
Requirements and guarantees Requires clauses are preconditions Ensures clauses are postconditions Who is responsible for requires clauses? Client (i.e., caller) Implementer Neither Both Discussion of consequences

5 Contract specifications
Requirements and guarantees Requires clauses are preconditions Ensures clauses are postconditions Who is responsible for requires clauses? Client (i.e., caller) Implementer Neither Both Consequences

6 Specification of Stacks
Mathematical modeling What can we think of stacks as “mathematically”?

7 Mathematical Strings Unlike sets, strings have order Notations
Example: Str(Z) for String of integers Notations Empty string (written empty_string or L) Concatenation ( alpha o beta ) Length ( |alpha| ) String containing one entry ( <5> )

8 Specification of IntStack Interface
Suppose IntStack is an interface uses Integer_Theory, String_Theory; Think of stacks of Integers as “math strings” of integers this: Str(Z); Specification of Constructor Initialization ensures this = empty_string; Exercises: Specification of other Stack operations

9 Specification of IntStack Interface
Operation push (int x); updates this; restores x; ensures this = <x> o #this; int Operation pop (); updates this; requires this /= empty_string; ensures #this = <result of pop()> o this; bool Operation is_empty(); preserves this; ensures result of is_empty = (this = empty_string);

10 Specification of IntStack Interface
Operation push (int x); updates this; restores x; ensures this = <x> o #this; int Operation pop (); updates this; requires this /= empty_string; ensures #this = <pop()> o this; bool Operation is_empty(); preserves this; ensures is_empty = (this = empty_string);

11 Java Specification Questions
What is the specification of “=“ to assign one IntStack object to another? If you defined a “clone” method, what is its specification? What are the advantages of using “=“ over “clone”? What are the advantages of using “clone” over equal?


Download ppt "Formal Specification of Java Interfaces"

Similar presentations


Ads by Google