Skip to content

Add LabelConverter for Category Interface #15

@programmerr47

Description

@programmerr47

As it appeared, there are cases, when many methods in interface use the same LabelConverter. In that case, a lot of duplicates appeared:

@HasPrefix
interface AnalyticsCar {
    fun sell(@Label(AdvertConverter::class) car: Car)
    fun buy(@Label(AdvertConverter::class) car: Car)
    fun review(@Label(AdvertConverter::class) car: Car)
    fun check(@Label(AdvertConverter::class) car: Car)
    fun utilize(@Label(AdvertConverter::class) car: Car)

    object CarConverter : TypedLabelConverter<Car> {
        override fun convertTyped(label: Car) =
                if (car.isBeauty()) "cool car"
                else if (car.isUgly()) "not so cool car"
                else "normal car"
    }
}

It seems that in that way we can add a global converter to GanalyticsSettings. But in other interfaces, we can have other converters for Car. That's why we need to think about the scope of the @Label annotation or introduce a @LabelConverter annotation.

In second case (which is preferable) we need to think how to pass several converters: each for each type of parameters.

As the result of aforementioned example we will have:

@HasPrefix
@LabelConverter(AdvertConverter::class)
interface AnalyticsCar {
    fun sell(car: Car)
    fun buy(car: Car)
    fun review(car: Car)
    fun check(car: Car)
    fun utilize(car: Car)

    object CarConverter : TypedLabelConverter<Car> {
        override fun convertTyped(label: Car) =
                if (car.isBeauty()) "cool car"
                else if (car.isUgly()) "not so cool car"
                else "normal car"
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions