Unlocking Kotlin: Dive into Classes, Interfaces & Inheritance

Опубликовано: 12 Май 2025
на канале: Tales from the jar side
312
13

Dive into the world of object-oriented programming in Kotlin as we explore classes, interfaces, and inheritance. We compare Kotlin's features with Java, delving into the Kotlin documentation to understand primary and secondary constructors, visibility modifiers, and initializer blocks. Discover how to define properties and create constructors, both primary and secondary. Learn about abstract classes, interfaces, the importance of the open keyword, and polymorphism. We also implement practical examples using IntelliJ, focusing on a shape hierarchy and testing using JUnit 5. Let's unravel the unique and fascinating aspects of Kotlin.

00:00 Introduction to Kotlin OOP
00:58 Understanding Kotlin Classes
02:16 Constructors and Initializers
04:48 Trailing commas
05:35 The constructor keyword
06:40 No new keyword
07:28 Inheritance and Abstract Classes
10:55 The Any class
11:35 Static binding by default
13:57 Overriding properties
15:27 Exploring Interfaces in Kotlin
17:11 Practical Example: Shape Hierarchy
18:59 Implementing the Comparable interface
22:29 Subclasses of Shape
26:36 Exploring the Drawable Interface
27:36 Implementing the Circle Class
28:17 Diving into Rectangles
29:26 Challenges with Triangles
31:48 The Motivation for Inheritance
32:48 SketchPad: A Collection of Shapes
34:22 Casting in Kotlin
39:07 Testing Shapes with JUnit
42:22 Parameterized Test in JUnit
47:28 The apply method
50:29 Final Thoughts and Conclusions