Presentation is loading. Please wait.

Presentation is loading. Please wait.

FEN 2013-05-01KbP: Seminar 2/JML-Intro1 JML Introduktion Specifikation af en Personklasse.

Similar presentations


Presentation on theme: "FEN 2013-05-01KbP: Seminar 2/JML-Intro1 JML Introduktion Specifikation af en Personklasse."— Presentation transcript:

1 FEN KbP: Seminar 2/JML-Intro1 JML Introduktion Specifikation af en Personklasse

2 FEN KbP: Seminar 2/JML-Intro2 public class Person { private spec_public String name; private int weight; public invariant && weight >= also ensures \result != null; public String toString() { return "Person(\“” +name+"\","+weight+")"; } ensures \result == weight; public int getWeight() { return weight; } requires kgs >= requires weight + kgs >= ensures weight == \old(weight + public void addKgs(int kgs) { weight= weight+kgs; } requires n != null && ensures && weight == public Person(String n) { name= n; weight= 0; }

3 FEN KbP: Seminar 2/JML-Intro3 Adskild specifikation og implementation public interface PersonIF { public invariant getWeight() >= also ensures \result != null; public pure String toString(); ensures \result >= 0; public int getWeight(); requires kgs >= ensures getWeight() == (\old(getWeight()) + public void addKgs(int kgs); } Specifikation i interface

4 FEN KbP: Seminar 2/JML-Intro4 public class PersonImp implements PersonIF { private spec_public String name; private int weight; public invariant && weight >= also ensures \result != null; public pure String toString() { return "Person(\"“ +name+"\","+weight+")"; } also ensures \result == weight; public int getWeight() { return weight; } public void addKgs(int kgs) { weight= weight+kgs; } requires n != null && ensures && weight == public PersonImp(String n) { name= n; weight= 0; } public class PersonMain1 { public static void main(String[] args) { PersonIF p= new PersonImp("Kurt"); p.addKgs(99); System.out.println(p.toString()); } Implementation i class interface som statisk type class som dynamisk Implementation i class Constructor skal etablere invarianten.


Download ppt "FEN 2013-05-01KbP: Seminar 2/JML-Intro1 JML Introduktion Specifikation af en Personklasse."

Similar presentations


Ads by Google