Attributes and behaviors

Every class contains attributes and behaviors. Attributes are the characteristics of the class that help to distinguish it from other classes. Behaviors are the tasks that an object performs. A person's attributes, for example, include their age, name, and height, while their behaviors include the fact that a person can speak, run, walk, and eat. In Kotlin, attributes are called properties and behaviors are called functions. Properties are presented with different data types, and behaviors are described using functions. When we map a Person class in Kotlin, it may look as shown in the following class diagram:

The properties of a class can be presented with different data types. For example, name might be presented as a Stringage might be presented as an Integer, and height might be presented as a Double. Similarly, a Person class can have functions with different implementations.

Before moving on, let's try to grasp these concepts one more time:

  • Class: A blueprint that defines the properties and functions of an object
  • Object: A noun, such as a car or a person, that assigns a value to properties
  • Property: Characteristics of an object that help to differentiate it from other objects
  • Function: An action performed by object
..................Content has been hidden....................

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