-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathAdapter.kt
More file actions
31 lines (24 loc) · 668 Bytes
/
Adapter.kt
File metadata and controls
31 lines (24 loc) · 668 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package design_patterns
/**
*
* Adapter is a structural design pattern that allows objects with incompatible interfaces to work together
*
*/
interface EnglishSpeaker {
fun speakEnglish(): String
}
class EnglishSpeakerImpl : EnglishSpeaker {
override fun speakEnglish(): String {
return "Hello, friend!"
}
}
interface SpainSpeaker {
fun speakSpanish(): String
}
class SpainSpeakerAdapter(private val englishSpeaker: EnglishSpeaker) : SpainSpeaker {
override fun speakSpanish(): String =
when (englishSpeaker.speakEnglish()) {
"Hello, friend!" -> "Hola, amigo!"
else -> "No te entiendo"
}
}