Chapter 4

  1. The object keyword is used to create a singleton class in Kotlin and a companion object is a special type of class that allows its members to behave like static objects.
  2. Kotlin provides sealed classes that are restricted to limited classes, and cannot be inherited further. Sealed classes are designed for situations in which a limited set of functionalities are required and no other class is allowed to be part of this set.
  3. In Kotlin, enum classes are similar to sealed classes, except that all the values of the enum class are the same type. The enum class is useful when the expected outcome is within a small set, such as a small range of colors, or the days of the week.
  4. When an object contains another object in its body, the relationship between them is called aggregation. This is a loosely coupled relationship between two objects, in which one object is not completely dependent on the other. Composition is an advanced form of aggregation, where two objects are highly dependent on each other. In aggression, one object contains the other object, whereas in composition, one object owns the other object. When the object that owns the other is destroyed, the object that is owned is also destroyed.
  5. Delegation refers to a situation in which we pass the responsibility to someone else. In Kotlin, properties can either be accessed directly, or by using the get and set functions with the backing field. When properties are not backed by their own class, but the responsibility is given to another class instead, these properties are called delegate properties.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.240.252