Bob
08/21/2024, 12:47 PMPablichjenkov
08/21/2024, 1:57 PMBob
08/21/2024, 7:12 PMPablichjenkov
08/21/2024, 7:21 PMPablichjenkov
08/21/2024, 7:23 PMpajatopmr
08/22/2024, 1:51 AMBob
08/22/2024, 1:54 AMBob
08/22/2024, 1:55 AMPablichjenkov
08/22/2024, 2:47 AMinterface ABC
object AnAbcObject() : ABC {
var something: Int = 1
fun someFun() { ... }
}
class B(abc: ABC) { ... }
// or
class C {
var abc: ABC? = null
setAbc(abc: ABC) { this.abc = abc }
}
In such a case that you have in your code class B or class C above. What is the benefit then of using an object.
The easy part of using an object is that you can use bellow non testable code:
AnAbcObject.something
AnAbcObject.someFun
If you are not doing above, why would you use an object in first place 🤷Pablichjenkov
08/22/2024, 2:49 AMset the mock
and clean the mock
before other tests start. If forgetting to clean up other tests might use previous test leftovers.Pablichjenkov
08/22/2024, 2:52 AMsharing mutable memory
. If you are not careful about it, threading issues immediately start showing up. Regular Classes don’t have that problem since each instance share a different memory space.(Well, unless you access the same instance from multiple threads)Bob
08/22/2024, 2:57 AMIn such a case that you have in your code class B or class C above. What is the benefit then of using an objectYa. i guess the only thing you’re getting is that an object would be lazily initialized.
Pablichjenkov
08/22/2024, 3:24 AM