/* +---------------+ | ConsList | +---------------+ +----| ISame fist | | | AList rest | | +---------------+ v +--------------------------+ | ISame | +--------------------------+ | boolean same(ISame that) | +--------------------------+ | / \ --- | -------------------- | | +--------------+ +--------------+ | Book | | Song | +--------------+ +--------------+ | String title | | String title | | String author| | int time | | int year | +--------------+ +--------------+ */ //to represent a nonempty list of ISame objects class ConsList implements AList{ ISame first; AList rest; ConsList(ISame first, AList rest){ this.first=first; this.rest=rest; } //is this non-emty list the same as that object public boolean same(ISame that){ if (that instanceof ConsList) return this.first.same(((ConsList)that).first) && this.rest.same(((ConsList)that).rest); else return false; } //does this non-emty list contain that object public boolean contains(ISame that){ if (this.first.same(that)) return true; else return this.rest.contains(that); } }