October 2018
Intermediate to advanced
370 pages
9h 15m
English
Information-hiding is a term that is used very often with regard to encapsulation. The idea behind information-hiding is that the class or object should not expose any information to the outside world unless it is necessary for another part of system. Let's try to understand this with an example:
class Person(pName: String, pAge: Int, pHeight : Double ) { var name : String = pName var age : Int = pAge var height : Double = pHeight init { require(name.trim().isNotEmpty()) {"Name should not empty"} require(age > 0 ) {"Age is not correct"} require(height > 0) {"Height is not correct"} }} fun main(args: Array<String>) { val person = Person("bob",40,6.1) println("Name ${person.name}, Age ${person.age} Height ${person.height}" ...Read now
Unlock full access