Encapsulating code helps to maintain a healthy code base. Kotlin extension functions and properties can aid you in doing so. Learn how to create them for a Kotlin Data Class in this video.
- We're here inside our solar system sample app.…And when you click on one of the planets,…it takes you to this detailed view,…where you get a description and…other information about the planet,…which includes its composition.…Let's see how this information is being provided right now,…and how we can take advantage of an extension function…in order to simplify the code.…So, we'll come over to Android Studio,…and we're here inside the PlanetDetailFragment.…This is the class that's responsible…for displaying that screen.…
If we scroll down to the onResume method,…we see here on line 62 some very simple logic…for determining a planet's composition.…If the planet is an inner planet, then it's terrestrial.…Otherwise, it's a gas giant.…Notice how this depends completely…on the inner property of the planet class.…So, it makes sense to move this logic there,…and we can do that by means of an extension function.…So, let's highlight this information here on line 62,…and copy it, and then we'll move over to the planet class.…
- What Kotlin has to offer
- Working with lambdas
- Common Android extension functions
- Kotlin Android Extensions overview
- Making use of the Anko library
- Working with coroutines
- Nullability and collections
Skill Level Intermediate
Android App Development: Data Persistence Librarieswith Annyce Davis4h 52m Intermediate
Developing AWS Lambda Functions with Kotlinwith Troy Miles1h 55m Intermediate
1. Kotlin Overview
2. Extension Functions and Properties
3. Incorporating Anko
4. Advanced Anko
5. Working with Collections
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.