The patterns solve the issue of object creation. Each of them is explained as follows:
- Telescoping constructor pattern: A class with a list of constructors where each constructor adds a new parameter. Nowadays it's considered an anti-pattern, but Android still uses it in a few places; for example, the android.view.View class:
val view1 = View(context)
val view1 = View(context, attributeSet)
val view1 = View(context, attributeSet, defStyleAttr)
- JavaBeans pattern: A parameterless constructor plus one or more setters methods to configure objects. The main problem with this pattern is that we can't say whether or not all the required methods have been called on an object, so it may be only partially constructed:
val animal = Animal() ...