Skip to content

Instantly share code, notes, and snippets.

View anitaa1990's full-sized avatar
🎯
Focusing

Anitaa Murthy anitaa1990

🎯
Focusing
  • Chennai
View GitHub Profile
// Solution step 1: Create an interface called Notifier.
// It has one method: jobAlert(String jobDescription)
interface Notifier {
fun jobAlert(jobDescription: String)
}
// Step II:
// Create an emailClient class that implements
// Notifier interface
class EmailClient : Notifier {
@anitaa1990
anitaa1990 / JobTracker.kt
Created August 13, 2024 10:40
JobTracker.kt
import kotlin.jvm.JvmStatic
/**
* Interface for generating job alerts
*/
interface AlertGenerator {
fun generateJobAlert(job: String): String
}
/**
import android.text.Editable
import android.text.TextWatcher
import android.widget.EditText
// We create an interface with one method
interface TextWatcherWithInstance {
fun onTextChanged(editText: EditText, s: CharSequence, start: Int, before: Int, count: Int)
}
// We create a custom class called MultiTextWatcher.
import android.text.Editable
import android.text.TextWatcher
import android.widget.EditText
editText.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
// Empty implementation
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
interface ClickListener {
fun onClick()
}
class Fragment1 : ClickListener {
override fun onClick() {
decrementClickCount()
//handle logic
}
interface ClickListener {
fun onClick()
}
class Fragment1 : ClickListener {
override fun onClick() {
//handle logic
}
fun decrementClickCount() {
interface TimeOfDay {
fun greet(): String
}
class TimeOfDayGreeting(private val timeOfDay: TimeOfDay) {
fun getGreetingFromTimeOfDay(): String {
return timeOfDay.greet()
}
}
class TimeOfDayGreeting {
private var timeOfDay: String? = null
/*
* Every time this method is called it will
* called an if else logic, which is in violation of the
* OCP principle.
*/
fun getGreetingFromTimeOfDay(): String {
return when (timeOfDay) {
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val movie = movies[position]
holder.title.text = movie.title
holder.rating.text = movie.rating
// all the logic is moved into util class...now is clean!
holder.authors.text = AppUtils.getGenres(movie)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val movie = movies[position]
holder.title.text = movie.title
holder.rating.text = movie.rating
// SRP violation, onBindViewHolder has only the responsibility to display data
// & not make data formatting operations
val genres = movie.genres