https://kotlinlang.org logo
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
benchmarks
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
confetti
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
lincheck
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by
Title
d

Dron Bhattacharya

02/20/2023, 4:54 PM
I want to learn design patterns with Kotlin. If there is any good learning source that can help me, it will be helpful if you can share it with me. I have come across a few blogs, but they are not informative enough.
d

Dron Bhattacharya

02/20/2023, 5:04 PM
I have already come across: 1. GitHub - dbacinski/Design-Patterns-In-Kotlin: Design Patterns implemented in Kotlin 2. Design patterns with Kotlin Part 1 In the GitHub source, the examples have much better examples compared to the medium article. But the GitHub source does not explain it well (for me, I am new to this)... is there something that has good real usecase examples like in that GitHub repo with more explanations? And if I want to practice, how should I proceed?
p

PoisonedYouth

02/20/2023, 5:05 PM
This is also a good resource for working with design patterns in Kotlin https://www.packtpub.com/product/kotlin-design-patterns-and-best-practices-second-edition/9781801815727
s

subrat prasad

02/20/2023, 7:37 PM
I started writing about design patterns in kotlin, literally yesterday. I felt the same challenge that I wanted to see real examples; which is what my focus will in my articles. Here is the first article https://medium.com/@humbleshuttler/design-patterns-in-kotlin-demystifying-singleton-pattern-7c0373d77fc7 PS: I have just started my journey on tech writing. Feedback is highly appreciated.
d

Dron Bhattacharya

02/21/2023, 10:27 AM
Code to an interface rather than to an implementation.
Can anyone explain this? Examples will also be helpful.
s

Sam

02/21/2023, 10:35 AM
A simple example would be to write functions that accept
List
(an interface) instead of
ArrayList
(a specific class that implements that interface). That makes your code more reusable and versatile, as it will be able to work with all types of lists.
fun printValues(items: List<String>) { ... } // good
fun printValues(items: ArrayList<String>) {... } // less good
d

Dron Bhattacharya

02/21/2023, 10:38 AM
Interfaces are mainly used for delegating class functions... Please bare with me if I am using the wrong terms (I am just learning).
c

CLOVIS

02/21/2023, 10:38 AM
Please don't send your messages to the channel. There are already people answering you, and you're spamming everyone else.
s

Sam

02/21/2023, 10:41 AM
“Delegating” might not be the exact right term, but I think you have the right idea 👍 interfaces generally contain abstract (unimplemented) functions, and the implementation is provided by one or more concrete subclasses. Programming to an interface is considered good practice because it means your code can work with any one of those concrete subclasses, not just the specific one you chose.
t

Ties

02/21/2023, 11:06 AM
It is that sense all about function signatures and how easy they are to use. if you have a function that takes a String and produces an Int, the signature is String -> Int. In this case you have the option to do ArrayList -> Unit, or List -> Unit. The last function will work for any implementation of List (e.g. ArrayList and LinkedList). In most cases the implementation of your function does not really case about a specific implementation of the list (if you just want to loop over it for example, you dont care if it is an ArrayList or a LinkedList). Therefore you can make your function more generic by using the interface instead of a specific implementation.
d

Dron Bhattacharya

02/21/2023, 1:38 PM
In most class diagrams I see that there is a get-method for each property of the class. But in Kotlin we can do
someClass.someProperty
to access it. Why need those get-methods in the class diagrams?
s

Sam

02/21/2023, 1:39 PM
Probably just for interoperability with Java. When you access a Kotlin property from Java you will see a public
get
and
set
method, and the underlying field will be private.
c

CLOVIS

02/21/2023, 1:39 PM
Class diagrams are not that standardized. Most people who use them have a Java background, where they are necessary, so they tend to write them anyway. You don't really have to bother too much with them, as you said in Kotlin they're not necessary
t

Ties

02/21/2023, 1:40 PM
Yeah, officially there is UML, but in practice most people keep them practical
c

CLOVIS

02/21/2023, 1:41 PM
@Ties I meant, UML doesn't go into the details of whether setters and getters are displayed, etc
UML also has "computed properties" marked as
/foo
, which in Kotlin are properties without a backing field (or with a backing field different enough that you can consider it's something else)
In general, don't take UML as "a golden truth of what your code should be like", it's more of a "here's the general idea, you can adapt the details to your situation", it's almost always fine to switch around what is a property or a method
Btw same thing with design patterns, it's not because they exist that you should use them! In practice, especially in Kotlin with all the syntax we have (
object
,
by
, DSLs…) it's rare to use a "proper design pattern"
After all, "design pattern" means "the way most of us agree upon to do something the language cannot do" (if the language could do it, it would be a language feature, not a design pattern)
d

Dron Bhattacharya

02/21/2023, 1:46 PM
OK