1 / 11

Formal Specification of Java Interfaces

Formal Specification of Java Interfaces. Jason Hallstrom and Murali Sitaraman Clemson University. Basics. An interface Describes what classes or components do Does not describe how they should do it An interface

jneil
Télécharger la présentation

Formal Specification of Java Interfaces

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 • An interface • 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 • 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; ensuresresult 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?

More Related