📖
kotlin-guidance
  • Intro
  • Basics
    • Functions
  • Libraries
    • Coroutines
  • Code Style Guide
    • Nomenclature
    • Structure
Powered by GitBook
On this page

Was this helpful?

  1. Code Style Guide

Structure

Class layout

The contents of a class should go in following order: 1. Property declarations 2. init blocks 3. Secondary constructor, if does exist 4. Overridden methods & interface implementation (keep the implementing members in the same order) 5. Class methods 6. companion object

class LoginFragment : BaseFragment {

    // 1. Property declarations
    private val viewModel by viewModels<LoginViewModel>()

    // 2. Initializer block
    init {
        contentRes = R.layout.fragment_login
        toolbarTitle = R.string.text_login_with
    }

    // 3. Secondary constructor

    // 4. Overridden methods
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
    }

    // 5. Class methods
    fun fetchMyLocationWithPermissionCheck() { }

    // 6. Companion object
    companion object { }
}
PreviousNomenclature

Last updated 3 years ago

Was this helpful?