is there a way to design a generic contract that w...
# getting-started
m
is there a way to design a generic contract that will be implemented using internal types? i.e:
Copy code
interface Entity
internal class MyClassEntity : Entity {}

interface Model
class MyClass {} : Model

interface Repository<M: Model, E: Entity> {
    fun constructEntity(model: M): E
}
basically I want to expose
MyClass
and implementations of
Repository
, but I want some way to construct entities internally and still have them be part of a contract
t
Extending your example:
Copy code
interface Entity
internal class MyClassEntity : Entity {}

interface Model
class MyClass : Model {}

interface Repository<M: Model, E: Entity> {
    fun constructEntity(model: M): E
}

// Will complain. Can't expose this because its exposing internal type MyClassEntity in the
// return value of constructEntity(...)
class MyRepository: Repository<MyClass, MyClassEntity> {
    override fun constructEntity(model: MyClass): MyClassEntity {

    }
}

// Won't complain. No internal type is being exposed here
class MyGenericEntityRepository<E: Entity>: Repository<MyClass, E> {
    override fun constructEntity(model: MyClass): E {
    }
}
Regarding
MyRepository
in that example ^, either
MyRepository
would have to be
internal
too, or
MyClassEntity
would have to be exposed