Delegation governs the transfer of authority /authority from one context to another for any object. Delegations can be used in permanent and interchangeable relationships for delegating classes and functions. Inheritance implementation of classes and functions can be modified with the help of delegation techniques and object-oriented programming languages, which are supported by default without boilerplate code. Delegation is used in Kotlin with the help of the "by" keyword.
There are two types of delegations:
Using Lazy () Function - Lazy is a lambda function that takes property as input and instead gives an example of lacy
Using Delegation.Observable () Function - Observable() function takes two arguments to initialize the object and returns to the called function. Syntax is the expression after the keyword "by" is delegated. The get () and set () methods of the variable will be delegated to its getValue () and setValue () methods as defined in the delegate class.
|