For example, in Retrofit package in kotlin or java it is used in network call i.e making a HTTP request to a server on the internet.
So, one of the functions in this package required me to pass an interface which have functions in it that will return a specific object type that Retrofit has already defined in it's package. This object is called Response<T>
with a Generic type as it's attribute/field.
The problem is why they wanted an interface but not a class. Because interface as i understand it, is that it's function cannot have a body i.e a definition. It can only have a declaration.
Does that means somewhere in their code they have a function that takes an interface
which is defined by me and then they inherits from that interface
that i supplied after that return or do what they wanted to do in that function i.e a void function.
so my question is, is this correct? or what actually they are doing with that interface
? because they need to inherit first and then instantiate. if this is correct then what sort of design pattern is this being called?
- what is the design pattern used?
- what they do with an
interface
that not yet have a definition?
Aucun commentaire:
Enregistrer un commentaire