2. Hi, I am John
- Android Developer
- Work on Rakuten Viki
- Use Kotlin for 2 years
- Linkedin:
https://www.linkedin.com/in/chang-john-0a95237a/
3. Outline
- Preface
- How to define a class?
- How to construct an instance?
- What’re class function and class property?
- Visibility and Encapsulation
- Properties
- Class property(getter and setter)
- Computed property
- Use Packages
- Guarding Against Race Conditions
4. Preface
Why we want to build object-oriented paradigm?
- in order to manage complexity
Why object-oriented paradigm deal with complexity easily?
- Not related with encapsulation, inheritance, polymorphism. It’s abstraction.
What’s abstraction?
- Distinguish what it need and what it doesn’t need when defining a class
5. Preface
What’s difference between Java and Kotlin for object-oriented-paradigm?
- Java forces developer implements explicitly. Kotlin hopes developer adopt
idiomatic(implicit)
For this book, What’s learning path for object-oriented-paradigm?
- Ch12, build a class(field vs property)
- Ch13, Initialization (primary, secondary, init block)
- Ch14, Inheritance (casting)
- Ch15, Object (different kinds of class)
- Ch16, Interfaces and Abstract Classes (Discrepancy)
9. Visibility and Encapsulation
- By default, any function and property without a visibility modifier is Public
- By default, Java uses Package Private visibility
-
11. What’s advantage of Properties?
1. Distinguish function and property more clearly
2. Related logic lives more close
3. Customization becomes more easy
4. Kotlin make it idiomatic, write less code
12. - Property can distinguish class property and computed property in class
- Class property Must assign property initializer so that compiler know that it must
create a field for this property
- Computed property MUST NOT give property initializer because its reference is
from result or delegation. Therefore, it has no field.
- var for writable(mutable) and val for read-only(immutable).
- var property owns getter/setter and val property only owns getter.