You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Regarding the sample solution provided, I am still very confused as to how the abstract class GradeableQuestion allows for the functionality of method mark() to only be accessible if and only if lock() has been done. Similarly, for the method answer().
The text was updated successfully, but these errors were encountered:
Haven't seen the solution but I'm guessing it has to do with the input and output types. For example in my solution I returned a gradeable type when a question uses lock(). And the mark() is only available in my gradeable interface (without other methods) so i cannot answer once a question is locked, but i can mark that question.
Take for example FillInBlank extends GradeableQuestion. When the question is locked, the method is called from the abstract class GradeableQuestion. The return type of .lock() is Gradeable, which is an interface. The interface Gradeable is the compile time type, which means only methods defined in the interface can be called. In the sample solution, the only method defined in the interface is .mark(), and thus .answer() cannot be called on. Hope this helps!
Different from the suggested answer, but what I did was to create a Question & LockedQuestion Interface.
Question contains lock() and answer(), while LockedQuestion contains mark()
answer() returns a LockedQuestion so this allows the question to access mark since its compile time type will now be LockedQuestion.
W/o answer, the question's compile time type will be Question hence it cant access mark.
I believe the suggested answer used a similar concept there
Source
Mock PA1 #1 Sample Solution
Description
Regarding the sample solution provided, I am still very confused as to how the abstract class GradeableQuestion allows for the functionality of method mark() to only be accessible if and only if lock() has been done. Similarly, for the method answer().
The text was updated successfully, but these errors were encountered: