Exercise X.2: In explaining how subtyping relates to the specification of types, Liskov and Wing mention both invariant properties and history constraints. Briefly explain the difference between these, giving an example of each.
Exercise X.3: Liskov and Wing's diamond diagram compares how the value of a subtype instance changes when using some new operation introduced in the subtype versus how the value of that same subtype instance would change using some explanatory succession of operations specified in the supertype. The value before the change is assumed to the same in either case; call the values after the changes A and B. Explain either why the following assertion is true or why it is false: the two resulting values, A and B, must be identical.
Exercise X.4:
The following AspectJ aspect could be added to the Jay interpreters
you are working with in the lab in order to print an error message if
any Value
object ever has its intValue
field
or boolValue
field retrieved without the type
of that
Value
being the appropriately matching Type
.
This aspect has two missing pointcut designators, indicated by
blanks. The first one should be filled in with the pointcut
designator that indicates any read access to the field
intValue
, of type int
, in the
Value
class. The second one should be filled in with the pointcut
designator that indicates any read access to the field
boolValue
, of type boolean
, in the
Value
class. You can find out the notation for these
field-access pointcuts in the second part of Ramnivas Laddad's article.
Fill in the blanks.
public aspect CheckValueGets { pointcut getInt(Value v) : _____________________________________ && target(v); pointcut getBool(Value v) : _____________________________________ && target(v); before(Value v) : getInt(v){ if(!v.type.isInteger()){ System.err.println("Illegal get of integer value at " + thisJoinPointStaticPart.getSourceLocation()); } } before(Value v) : getBool(v){ if(!v.type.isBoolean()){ System.err.println("Illegal get of boolean value at " + thisJoinPointStaticPart.getSourceLocation()); } } }