Skip to content

Cannot mock classes marked final #762

Answered by lcobucci
ol1s asked this question in Q&A
Jun 15, 2021 · 1 comments · 4 replies
Discussion options

You must be logged in to vote

@ol1s making my classes final is the best way to make my design choices explicit.

If I leave the class open for inheritance, it becomes an extension point and people may rely on its internals do do other things. That also means that if I decide to make chances to how these classes work, it will be a BC-break.
I don't want that to happen because it creates more work for me in the end. So, no, I won't consider removing final from classes.

The extension points in the library are explicitly defined with interfaces and you can surely mock these interfaces. The question is, though: when should you mock them? Mocking is great until it becomes extremely painful =)

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@ol1s
Comment options

@lcobucci
Comment options

@ol1s
Comment options

@lcobucci
Comment options

Answer selected by lcobucci
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #761 on June 15, 2021 14:56.