Skip to content

Instantly share code, notes, and snippets.

View alibahaaa's full-sized avatar
❤️‍🔥
Coding with love and passion

Ali Baha alibahaaa

❤️‍🔥
Coding with love and passion
View GitHub Profile
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
}
interface Target {
fun request()
}
class Adaptee {
fun specificRequest() {
// implementation
}
}
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!!
}
}
class Singleton private constructor() {
companion object {
private var instance: Singleton? = null
fun getInstance(): Singleton {
if (instance == null) {
instance = Singleton()
}
return instance!!
}
}
class Client {
fun operation(prototype: Prototype) {
val prototypeClone = prototype.clone()
// use the clone
}
}
class ConcretePrototype : Prototype {
var attribute: String = ""
override fun clone(): Prototype {
val clone = ConcretePrototype()
clone.attribute = this.attribute
return clone
}
}
interface Prototype {
fun clone(): Prototype
}
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')"
}
}
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)
interface AlertDialog {
fun show()
}
class MaterialAlertDialog : AlertDialog {
override fun show() {
println("Showing Material Design Alert Dialog")
}
}