Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question regarding lock() and mark() for Mock PA1 #1 Sample Solution #72

Closed
Noel-Lee opened this issue Mar 2, 2022 · 3 comments
Closed

Comments

@Noel-Lee
Copy link

Noel-Lee commented Mar 2, 2022

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().

@LauWyeRock
Copy link

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.

@szeying02
Copy link

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!

@jlee1007
Copy link

jlee1007 commented Mar 3, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants