You are currently viewing Question about companion object

Question about companion object

Hello guys,

I’m currently practicing android dev and making an app using MVVM pattern. For model classes I also have repositories and inside them I have companion objects.
If I’m putting an attribute inside a companion object (for example var count: Int), should I make it a private attribute and create a getter and setter inside companion object or just not make it public (so that I can write for example ExampleRepository.count instead of ExampleRepository.getCount())? I need to increase this attribute later inside other activites based on user clicks inside a view (number of correct answers in a quiz). I also have a viewmodel to return this info in other activities/fragments where I need it.

Thank you in advance.

submitted by /u/temp000321
[link] [comments]