https://kotlinlang.org logo
Title
f

fstn

10/15/2017, 11:22 AM
Is it a bad thinks to use a lot object instead of classes?
f

feroz_baig

10/15/2017, 11:24 AM
If the objects are related, you can bundle them in a class. Would be more structured, isn't it?
f

fstn

10/15/2017, 11:25 AM
mmmm... for exemple I have a Vertx Verticle that use a service and a manager
the service and the manager are services
they are like utils classes
for example :
package fstn.vertxFlow.config.manager

import io.vertx.rxjava.core.Vertx
import io.vertx.rxjava.core.buffer.Buffer
import rx.Observable


/**
 * Use to read or write bpmn flow file
 * @author fstn
 */
class BpmnManager {

    fun get(flowName:String): Observable<Buffer> {
        return Vertx.vertx().fileSystem()
                .rxReadFile(“$flowName.bpmn”)
                .doOnError { throw UnableToReadConfigurationException(flowName) }
                .toObservable()
    }

    fun set(flowName:String,flowContent:String): Observable<Void> {
        return Vertx.vertx().fileSystem()
                .rxWriteFile(“$flowName.bpmn”, Buffer.buffer(flowContent))
                .doOnError { throw UnableToWriteConfigurationException(flowName) }
                .toObservable()
    }

    class UnableToWriteConfigurationException(flowName: String) : RuntimeException(flowName)
    class UnableToReadConfigurationException(flowName: String) : RuntimeException(flowName)
}
f

feroz_baig

10/15/2017, 11:27 AM
am not familiar with rx 😅
😅 1
f

fstn

10/15/2017, 11:28 AM
the get return the content of the file
and the set write into the file
should I use a class or an object ?
or a companion object
s

stantronic

10/15/2017, 11:30 AM
Personally I think you're fine using object - a class with companion would be overkill for something like this
alternatively you could just use a bunch of package-scoped functions, as there doesn't seem to be any persisted state here
f

fstn

10/15/2017, 11:32 AM
yes there is no persistent data
but Intellij doesn’t import automaticaly package of function
so it’s very boring
that’s why I prefere to use classes or objects 😂
s

stantronic

10/15/2017, 11:33 AM
it should - it works for me
f

fstn

10/15/2017, 11:33 AM
Am I wrong?
Mine doesn’t want to
s

stantronic

10/15/2017, 11:34 AM
strange
i guess the function names are too short for the intellisense to kick in
I use slightly longer names, and the autocoplete starts suggesting them
f

fstn

10/15/2017, 11:47 AM
Maybe 😉