https://github.com/professordeveloper/kotlin-pattern
https://github.com/professordeveloper/kotlin-pattern
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/professordeveloper/kotlin-pattern
- Owner: professorDeveloper
- Created: 2022-07-15T10:43:54.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-07-15T10:44:17.000Z (over 3 years ago)
- Last Synced: 2025-04-12T13:09:07.151Z (10 months ago)
- Language: Kotlin
- Size: 48.8 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Pattern-Kotlin
My Best The Best
example
package amaliyot7
import FloppyDisk
fun main(args: Array) {
var cabbinet = Cabbinet()
cabbinet.add(FloppyDisk())
cabbinet.add(HardDrive())
cabbinet.add(Memory())
println("Cabinet Price: ${cabbinet.getPrice()}")//Bizga Barcha Mahsulotlarni Yigindisini ekranga chiqaradi
}
//Cabinent
class Cabbinet : Composite("cabbinet")
//open class Compsoite
package amaliyot7
/*
[composite] Design Pattern nol yoki undan ko'p o'xshash ob'ektlarni yaratish uchun ishlatiladi,
shunda ularni bitta ob'ekt sifatida boshqarish mumkin !
Masalan:
*/
open class Composite(name: String) : Equipment(0, name) {
val equipments = ArrayList()
fun add(equipment: Equipment) {
this.equipments.add(equipment)
}
override fun getPrice(): Int {
return equipments.sumOf { it.getPrice() }
}
}
//open class equipments
open class Equipment(private var price: Int, private var name: String) {
open fun getPrice(): Int = price
}