hi, i just read <https://maxkim.eu/things-every-ko...
# coroutines
t
hi, i just read https://maxkim.eu/things-every-kotlin-developer-should-know-about-coroutines-part-2-coroutinescope which says that one shouldn't implement the
CoroutineScope
interface anymore. unfortunately it doesn't say anything about the WHY despite using the builder function would be more straightforward. why is it more straightforward?
n
Unless external code launching coroutines is part of your use case, you probably don't want to implement
CoroutineScope
. Do you really want people to do this:
Copy code
val foo = MyClassThatUsesCoroutinesInside()
foo.launch { ... }
t
but why?
n
https://en.wikipedia.org/wiki/Encapsulation_(computer_programming) Code is easier to maintain when private details are not exposed to callers.
t
oh so its all about the observability wether or not the class implements the interface
n
Yeah, implementing an interface just so you can use it internally often considered an anti-pattern.