This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface RecyclerViewAdapter { | |
fun getItemCount(): Int | |
fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) | |
} | |
class ListAdapter(private val items: List<String>) : RecyclerViewAdapter { | |
override fun getItemCount(): Int { | |
return items.size | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Target { | |
fun request() | |
} | |
class Adaptee { | |
fun specificRequest() { | |
// implementation | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DatabaseHelper private constructor(context: Context) { | |
companion object { | |
private var instance: DatabaseHelper? = null | |
fun getInstance(context: Context): DatabaseHelper { | |
if (instance == null) { | |
instance = DatabaseHelper(context) | |
} | |
return instance!! | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Singleton private constructor() { | |
companion object { | |
private var instance: Singleton? = null | |
fun getInstance(): Singleton { | |
if (instance == null) { | |
instance = Singleton() | |
} | |
return instance!! | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Client { | |
fun operation(prototype: Prototype) { | |
val prototypeClone = prototype.clone() | |
// use the clone | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ConcretePrototype : Prototype { | |
var attribute: String = "" | |
override fun clone(): Prototype { | |
val clone = ConcretePrototype() | |
clone.attribute = this.attribute | |
return clone | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Prototype { | |
fun clone(): Prototype | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User { | |
var name: String = "" | |
var email: String = "" | |
var age: Int = 0 | |
var address: String = "" | |
override fun toString(): String { | |
return "User(name='$name', email='$email', age=$age, address='$address')" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Product { | |
var partA: String = "" | |
var partB: String = "" | |
var partC: String = "" | |
} | |
interface Builder { | |
fun buildPartA(part: String) | |
fun buildPartB(part: String) | |
fun buildPartC(part: String) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface AlertDialog { | |
fun show() | |
} | |
class MaterialAlertDialog : AlertDialog { | |
override fun show() { | |
println("Showing Material Design Alert Dialog") | |
} | |
} |