If we do not want to initialise a variable inside constructor or at start of class then we have two option to initialise details are given below, i’ll try to keep this short and simple.

  1. lateinit (mutable)
  2. lazy (immutable)

How to initialise lateinit and lazy

lateinit (can be used only…

When to use Builder Design Pattern

  1. To optimize Telescoping constructor.
  2. Build immutable object
  3. If field will increase in future we need not to edit all previous classes.

How to use Builder Design Pattern

suppose we have a Student class where we want to initialise it using constructor

class Student {…

Why not MVC (Model View Controller) ?

  1. No Separation of concerns

e.g: lifecycle and business logic

2. Difficult to test and debug.

3. Difficult to mange because of large class size.

Model ← → Controller← →View

Model and View both talks to controller regarding update, user action, notify etc. …

There are 4 persons who wants to cross the bridge A, B, C and D. but bridge cannot be crossed without the torch because its night time and at a time maximum 2 person can cross the bridge. the problem is to find minimum time required to cross bridge.

  1. A takes 2 minute to cross the bridge.
  2. B takes 3 minutes to cross the bridge.
  3. C takes 4 minutes to cross the bridge.
  4. D takes 7 minutes to cross the bridge.

Solution :

firstly A and B will cross the bridge with torch(time took 3 minute)

then B will return back with torch(time took 3minute)

then C and D will cross the bridge (time took 7 minute)

the A will return back and cross the bridge with B(time took 5 minute)

total time took — 18 minute

Rahul Sharma

Lead Android Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store