SWE 619 In Class Exercise Number 3
September 19, 2017


Consider the code:

public class Members {
    // Members is a mutable record of organization membership
    // AF: Collect the list as a set
    // rep-inv1: members != null
    // rep-inv2: members != null && no duplicates in members
    // for simplicity, assume null can be a member...

    List<Person> members;   // the representation

    //  Post: person becomes a member
    public void join (Person person) { members.add   (person);}

    //  Post: person is no longer a member
    public void leave(Person person) { members.remove(person);}

  1. Analyze these 4 questions for rep-inv 1.

  2. Repeat for rep-inv 2.

  3. Recode join() to make the verification go through. Which rep-invariant do you use?

  4. Recode leave() to make the verification go through. Which rep-invariant do you use?