Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.lyjak.anna.exercisesolid.dry.fixConsts.good

class DateUtils {

val CONS = 1000 * 60 * 60 * 24

fun getDaysInMiliseconds(miliseconds: Long): Long {
return miliseconds / CONS
}

fun getMilisecondsInDays(days: Long): Long {
return days * CONS
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.lyjak.anna.exercisesolid.dry.fixPolymorphism.good

class Actor(val name: String)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.lyjak.anna.exercisesolid.dry.fixPolymorphism.good

class Article(
index: Long, title: String, description: String, year: Int,
author: String,
val pages: Int
) : Literature(index, title, description, year, author)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.lyjak.anna.exercisesolid.dry.fixPolymorphism.good

class Book(
index: Long, title: String, description: String, year: Int,
author: String,
val topics: List<String>
) : Literature(index, title, description, year, author)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.lyjak.anna.exercisesolid.dry.fixPolymorphism.good

class Film(
index: Long, title: String, description: String, year: Int,
val director: String, val actors: List<Actor>, val duration: Int
) : Publication(index, title, description, year)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.lyjak.anna.exercisesolid.dry.fixPolymorphism.good

open class Literature(
index: Long, title: String, description: String, year: Int,
val author: String
) : Publication(index, title, description, year) {

fun print() {
//get Literature position from database by index and print to file
}

override fun getSummary(): String { // this override wasn't necessary
return "$title by $author ($year) \n $description"
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.lyjak.anna.exercisesolid.dry.fixPolymorphism.good

class Music(
index: Long, title: String, description: String, year: Int,
val band: String, val duration: Int
) : Publication(index, title, description, year)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.lyjak.anna.exercisesolid.dry.fixPolymorphism.good

open class Publication(val index: Long, val title: String, val description: String, val year: Int) {

open fun getSummary(): String {
return "$title ($year) \n $description"
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.lyjak.anna.exercisesolid.kiss.good

import java.util.Date

object DateUtils {

private const val MILLISECONDS_IN_HOUR: Long = 1000 * 60 * 60

fun isPast(timestamp: Long): Boolean = timestamp < System.currentTimeMillis()

fun isPast(date: Date): Boolean = date.time < System.currentTimeMillis()

fun getFullDays(timestamp: Long): Long = timestamp / MILLISECONDS_IN_HOUR

fun getFullDays(date: Date): Long = date.time / MILLISECONDS_IN_HOUR
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.lyjak.anna.exercisesolid.kiss.good

class NumberManager(private var number: Int) {

companion object {
const val ONE_HUNDRED = 100
}

fun multiplyNumber(value : Int) {
number *= value
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.lyjak.anna.exercisesolid.solid.d.good

class DotMatrixPrinterPrinter : Printer {

override fun print(sth: String) {
println(". . $sth . .")
}

}

class ConsolePrinter : Printer {

override fun print(sth: String) {
println(sth)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.lyjak.anna.exercisesolid.solid.d.good

interface Printer {
fun print(sth: String)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.lyjak.anna.exercisesolid.solid.d.good

class PrinterDesk(private val printer: Printer) {

fun printFile() {
printer.print("File Content")
}

}


fun test() {
val dotPrinter = DotMatrixPrinterPrinter()
val consolePrinter = ConsolePrinter()

val printerDesk = PrinterDesk(consolePrinter)

printerDesk.printFile()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.lyjak.anna.exercisesolid.solid.i.good

class AndroidComponent : Touchable, Swipable, Validator {

override fun touch(event: String) {
println("Touch Event Fired")
}

override fun swipe(event: String) {
println("Swipe Event Fired")
}

override fun validate() {
println("All UI is valid")
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.lyjak.anna.exercisesolid.solid.i.good

class DesktopComponent : Touchable, Validator {

override fun touch(event: String) {
throw UnsupportedOperationException("touch not supported")
}

override fun validate() {
println("All UI is valid")
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.lyjak.anna.exercisesolid.solid.i.good

interface Mouseoberable {
fun mouseover(event: String)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.lyjak.anna.exercisesolid.solid.i.good

interface Swipable {
fun swipe(event: String)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.lyjak.anna.exercisesolid.solid.i.good

interface Touchable {
fun touch(event: String)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.lyjak.anna.exercisesolid.solid.i.good

interface Validator {
fun validate()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.lyjak.anna.exercisesolid.solid.l.good

open class Rectangle(var width: Double = 0.0, var height: Double = 0.0): Shape {

override fun calculateArea() = width * height

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.lyjak.anna.exercisesolid.solid.l.good

interface Shape {
fun calculateArea(): Double
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.lyjak.anna.exercisesolid.solid.l.good

class Square(side: Double) : Rectangle(side, side)

fun test() {
val square = Square(1.0)
square.calculateArea()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.lyjak.anna.exercisesolid.solid.o.good

class Car(name: String?, price: Double) : Product(name, price){
override fun getTotal(): Double = price * 1.60 * 1.18
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.lyjak.anna.exercisesolid.solid.o.good

class Electronics(name: String?, price: Double) : Product(name, price) {
override fun getTotal(): Double = price * 1.18
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.lyjak.anna.exercisesolid.solid.o.good

class Food(name: String?, price: Double) : Product(name, price){
override fun getTotal(): Double = price + price * 0.08
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.lyjak.anna.exercisesolid.solid.o.good

abstract class Product(val name: String? = null, var price: Double = 0.0) {
abstract fun getTotal(): Double
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.lyjak.anna.exercisesolid.solid.o.good

class ShoppingCartService {

fun calculateTotalOrder(products: List<Product>): Double {
var orderTotal = 0.0
products.forEach { product ->
orderTotal += product.getTotal()
}
return orderTotal
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.lyjak.anna.exercisesolid.solid.s.good

data class Author(val name: String, val surname: String) : Introduce {

override fun introduce() = "$name $surname"

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.lyjak.anna.exercisesolid.solid.s.good

data class Book(
val author: Author,
val bookName: String? = null,
val text: String? = null
) : Introduce, Printer {

override fun introduce(): String = "This is $bookName book written by ${author.introduce()}"

override fun print() = println(text)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.lyjak.anna.exercisesolid.solid.s.good

interface Introduce {
fun introduce(): String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.lyjak.anna.exercisesolid.solid.s.good

interface Printer {
fun print()
}