From the course: Build Spring Boot Apps with the Kotlin Programming Language
Unlock this course with a free trial
Join today to access over 22,600 courses taught by industry experts.
Alternative class design
From the course: Build Spring Boot Apps with the Kotlin Programming Language
Alternative class design
- [Instructor] Now they're not, really doing anything that sensible. So I'm going to remove these. But I'd like to show you an alternative, for how we could have created this customer class. I'm not going to say that this alternative is better, but I'd like to go through it, because it will help us understand, exactly how all these different things, these fields of constructors, and edit blocks are really working. So let's create this as a second class, within the same file. And well call this alternative customer. (typing quickly) Now in this version the optional field, the address, I'm going to make that a field within the class, rather than part of the primary constructor. So we're going to have primary constructor, consisting of the name as a string, and the age as an integer. (typing quickly) And in fact I'll change that to a Var, so we're doing exactly the same thing. And then within the code for the class itself, is where I'm going to define the address. And I'm going to define…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Project structure and packages2m 5s
-
(Locked)
The class declaration and class-level attributes3m 31s
-
Instantiating a class and accessing class-level attributes2m 14s
-
(Locked)
Creating a simple constructor5m 7s
-
(Locked)
Secondary constructors5m 20s
-
(Locked)
Alternative class design5m 3s
-
(Locked)
Overriding getters and setters7m 21s
-
(Locked)
Functions within a class2m 57s
-
(Locked)
Static functions3m 28s
-
(Locked)
Data classes7m 32s
-
(Locked)
-
-
-
-
-
-
-
-
-
-
-
-
-
-