Skip to content

Instantly share code, notes, and snippets.

SingletonClass.doing()
object SingletonClass {
fun doing() {}
}
val womenPerson = PersonFactory.makePerson(Gender.WOMEN)
val menPerson = PersonFactory.makePerson(Gender.MEN)
// 1 - Declare Interface
interface Person
// 2 - Declare Classes
class Women : Person
class Men : Person
// 3 - Declare Enum
enum class Gender {WOMEN , MEN}
// 4 - Declare Abstract class
abstract class PersonFactory {
companion object {
val firstPerson = Person.Builder(
name = "Bob", //Necessary
family = "Ras") //Necessary
.age(32) //Optional
.email("[email protected]") //Optional
.phoneNumber("+19094XXX") //Optional
.nationalCode("09640XXXXX") //Optional
.create() //Create
val secondPerson = Person.Builder(
name = "Alis", //Necessary
class Person(
val name:String,
val family:String,
val age:Int,
val nationalCode: String?,
val email: String?,
val phoneNumber: String?
) {
// 1 - Private constructor
private constructor(builder: Builder) : this (
val firstPerson = Person(
name = "Bob", //Necessary
family = "Ras", //Necessary
age = 32, //Optional
email = "[email protected]", //Optional
phoneNumber = "+19094XXX", //Optional
nationalCode = "09640XXXXX" //Optional
)
val secondPerson = Person(
name = "Alis", //Necessary
@Adnan9011
Adnan9011 / Builder
Last active May 21, 2022 15:03
Builder
data class Person(
val name:String,
val family:String,
val age:Int = 0,
val nationalCode: String? = null,
val email: String? = null,
val phoneNumber: String? = null
)