Posts

ViewHolder Pattern

ViewHolder design pattern is used to speed up rendering of your ListView  - actually to make it work smoothly, findViewById is quite expensive (it does DOM - Data Object Model parsing) when used each time a list item is rendered, it must traverse our layout hierarchy  and also instantiate objects .  Since lists can redraw its items quite frequently during scrolling such overhead might be substantial.  The ViewHolder pattern is solely to reduce the number of view.findViewById(int)  calls we make.  The ViewHolder pattern only works when we take advantage of view recycling The ViewHolder design pattern enables you to access each list item view without the need for the look up, saving valuable processor cycles.  Specifically, it avoids frequent call of findViewById() during ListView scrolling, and that will make it smooth Without the ViewHolder Design Pattern Okay, let’s dig it out and see how it works  without  the ViewHolder pattern. Let’s take...

Singleton in Kotlin - Companion Object and Operator fun invoke

Java Way :  public class Singleton { private static Singleton INSTANCE = null; // other instance variables can be here private Singleton () {} ; public static synchronized Singleton getInstance () { if ( INSTANCE == null ) { INSTANCE = new Singleton() ; } return ( INSTANCE ) ; } // other instance methods can follow } 2. class Manager  private constructor () { // We do not have static keyword in Kotlin. // We use Companion Object in Kotlin which is a replacement of static companion object {           private var instance : Manager? = null // Already instantiated? - return the instance // Otherwise instantiate in a thread-safe manner fun getInstance() = synchronized(this) { // This makes Thread safe               if(instance == null)                    instanc...

MVVM - Model View ViewModel

Disadvantages of MVVM: Communication between various MVVM components and data binding can be painful Code reusability of views and view model is difficult. Managing view models and their state in nested views and complex UI’s is difficult MVC vs MVVM MVC architecture has “one to many” relationships between Controller & View MVVM architecture, “one to many” relationships between View & View Model. MVC framework is an architectural pattern that separates an applications into three main logical components Model, View, and Controller. MVVM facilitates a separation of development of the graphical user interface with the help of mark-up language or GUI code In MVC, controller is the entry point to the Application In MVVM, the view is the entry point to the Application. MVP vs MVVM In MVP, the View and Presenter have references to each other (generally through an interface). With MVVM, only the View has a reference to the ViewModel. The ViewModel knows nothing about the View - it simp...

Kotlin & Coroutines

Image
Kotlin is a statically typed, open-source programming language that runs on the JVM and can be used anywhere Java is used today. It can be compiled using Java source code The most popular features of kotlin are: Kotlin is Concise:  reduces the writing of the extra codes Compact code:  Kotlin is an OOPs-based programming language. Less number of code compared to java. Kotlin is Simple:  Compiling the code is simple, resulting in improved performance for Android development. Null safety:  Kotlin is a null safety language. It aims to eliminate the NullPointerException (null reference) from the code. Java Interoperability:  Kotlin provides full interoperability for Java code. Java code can utilize Kotlin code, and Kotlin code can use Java code. Compilation Time:  Kotlin is faster and better than Java in terms of its performance and fast compilation time. Default & Named Parameters Difference between Val and Constant Both  val  and  const ...