Gå til innhold

Anbefalte innlegg

Jeg har en oppgave som jeg trenger litt hjelp til å komme i gang med, håper noen har tid til og hjelpe meg litt.

 

Klassene er skrevet i et språk som er ca Java

public class TotalMap {

///ensures forall z : lookup(z)==z
public TotalMap(){...}

///ensures result!=null
public Integer lookup(Integer x){...}

///ensures lookup(x)==y
///ensures forall z : x!=z => lookup(z)==old(lookup(z))
public void set(Integer x,Integer y){...}

///ensures result==true
public boolean has(Integer x){...}
...
}


public class PartialMap {

///ensures forall z : lookup(z)==null
///ensures forall z : !has(z)
public PartialMap(){...}

///ensures has(x) <==> result!=null
public Integer lookup(Integer x){...}

///ensures lookup(x)==y
///ensures forall z : x!=z => lookup(z)==old(lookup(z))
///ensures forall z : has(z) <==> old(has(z)) || z==x
public void set(Integer x,Integer y){...}

public boolean has(Integer x){...}
...
}


public class Set{

///ensures forall z : !has(z)
public Set(){...}

public boolean has(Integer x){...}

///ensures forall z : has(z) <==> (old(has(z)) || z==x)
public void include(Integer x){...}

///ensures forall z : has(z) <==> (old(has(z)) && !z==x)
public void exclude(Integer x){...}
...
}

The complete public interfaces of the classes are shown, but they may have private elds and methods which are not shown.

Første spørsmål er at jeg skal liste alle "behavioral subtyping relationships" mellom klassene:

  • has(): TotalMap => PartialMap, TotalMap => Set
  • set(): PartialMap => TotalMap
  • lookup(): PartialMap => TotalMap
  • constructor?

Er usikker på om de ekstra postconditions i set() og lookup() styrker postcondition eller ikke, selv om jeg har tatt utgangspunkt i det. Noen tanker?

 

In the following sections assume our language includes the keyword inherits which functions like extends except it does not create a subtype relation but just an inheritance relation. Each of the sections is independent of the others:

  • Implement TotalMap using inheritance or subclassing from PartialMap with maximal code reuse and without adding any new elds.
  • Implement PartialMap using inheritance or subclassing from TotalMap with maximal code reuse and without adding any new elds. Assume that Integer is unbounded.
  • Implement Set using inheritance or subclassing from TotalMap with maximal code reuse and without adding any new elds.
  • Implement Set using inheritance or subclassing from PartialMap with maximal code reuse and without adding any new elds.

Jeg trenger litt hjelp til å komme i gang med denne oppgaven, så hvis noen har noen tips så blir jeg veldig glad!

Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
×
×
  • Opprett ny...