
IUpdateStrategy's, couldn't a Multistrategy hold a Multistrategy, which is holding a Multistrategy (or two) which is hold a Multistrategy, which is holding. If it could, it would not be possible to instantiate an object of that class. b) No, a concrete class can not have abstract methods. That is just the way it is - if it couldn't have concrete methods it would almost be the same as a Java interface. Use the same techniques as before: strategies that hold strategies.īut isn't a MultiStrategy an IUpdateStrategy iteself? That is, since a MultiStrategy holds a) Yes, an abstract class can have concrete methods. An explicitĬast is required to supress the compile time error ( aop = (AddOp) bop), but may trigger a run-time error if indeed the instance referred to by bop is not of type The above assignment will cause a compile time error because the compiler cannot know if the assignment is possible. Another way of saying this is thatĪ superset contains its subsets but not the other way around.

Object of the type of any subclass, but a variable of the type of a particular subclass cannot necessarily reference something of the type of its superclass. That is, a variable of the type of the superclass can always reference an staticly typed as such), which and does not necessarily referenceĪn object of type AddOp. Not as written, because bop is a variable of type IBinaryOp (i.e. Yes! bop is a variable of type IBinaryOp, and aop is defined as referencing an AddOp object, which is an No, because aop is a variable of type AddOp, and MultIOp is not an AddOp, so aop cannot reference an instance of MultOp. Yes, because aop is a variable of type AddOp, and thus can reference an instance of the same type. If we had MultOp mop = new MultOp(), then mop.getDescription() is perfectly legal. This is because the static typing of bop tells the compiler that it references an IBinaryOp, not the particular concrete type of the object it currently references. No, because bop is a variable of type IBinaryOp, which is not defined as having a getDescription method. It is impossible to tell because it depends on the exact type of the object instance to which myOp refers.

The result is 15 because bop now refers to an MultOp instance, whose apply method multiplies its two input values. The result is 8 because bop refers to an AddOp instance, whose apply method adds its two input MultOp is an IBinaryOp, so bop can reference it. Yes, for the same reasons as the previous exercise! MultOp is an concrete class and can be instantiated. AddOp is an IBinaryOp (technically, AddOp implements the IBinaryOpinterface), so bop can reference it.

Yes! AddOp is an concrete class and can be instantiated. IBinaryOp is an interface and does not specify any actual executable code, so it cannot be instantiated. Furthermore we could make a note to check that negative values are handled correctly.Available under Creative Commons-ShareAlike 4.0 International License. Making a walk through of testMinus() obviously makes us want to take a closer look at the minus() method. The testMinus() method is similar in structure to the testPlus() method.
#BLUEJ EXERCISE SOLUTIONS CODE#
It is not the same result as was returned by testAll().Ĭalling testPlus() one more time returns 7.Īccording to the source code it should return 7. There is no way to know (just from the test output) that the tests passed, because we only get the test result value. The terminal window shows: Testing the addition operation.

The test result window reports one failure and shows a big red bar.
#BLUEJ EXERCISE SOLUTIONS MANUAL#
The regression test we have done so far still requires manual inspection of the output. test zero and negative values for duration and time.Ī positive test could be to test that appointments longer than an hour has the correct duration after being inserted. test how the application handles a 'null' object as an appointment.
