Inner classes
In this project, we will use a type of class we have not seen yet – an inner class. Suppose that we have a regular class called SomeRegularClass
, with a property called someRegularProperty
, and a function called someRegularFunction
, as shown in this next code:
class SomeRegularClass{ var someRegularProperty = 1 fun someRegularFunction(){ } }
An inner class is a class that is declared inside of a regular class, like in this next highlighted code:
class SomeRegularClass{ var someRegularProperty = 1 fun someRegularFunction(){ } inner class MyInnerClass { val myInnerProperty = 1 fun myInnerFunction() { } } }
The preceding highlighted code shows an inner class called MyInnerClass
, with a property called myInnerProperty
, and a function called myInnerFunction
.
One advantage is that the outer class can use the properties and functions of the inner class by declaring an instance of it, as shown highlighted in the next...