Skip to content

Instantly share code, notes, and snippets.

View igorwojda's full-sized avatar

Igor Wojda igorwojda

View GitHub Profile
@igorwojda
igorwojda / kotlin-law-of-demeter.kt
Last active February 7, 2017 07:10
Kotlin examples of following/violation the Law of Demeter LoD (a.k.a. Principle of Least Knowledge PoLK)
/**
* Kotlin examples of following/violation Law of Demeter LoD (a.k.a. Principle of Least Knowledge PoLK)
*
* Law of Demeter for functions requires that a method m of an object O may only invoke the
* methods of the following kinds of objects:
* 1. O itself
* 2. m's parameters
* 3. Any objects created/instantiated within m
* 4. O's direct component objects
* 5. A global variable, accessible by O, in the scope of m
@igorwojda
igorwojda / ProfilePresenterTest_Java_JUnit.java
Created August 2, 2017 08:33
Java JUnit Test when_take_view_register_event_bus
@Test
public void when_take_view_register_event_bus() {
// given
profilePresenter.takeView(mockView);
// then
then(mockEventBus).should().register(profilePresenter);
}
@igorwojda
igorwojda / ProfilePresenterTest_Kotlin_JUnit.kt
Created August 2, 2017 08:33
Kotlin JUnit Test when_take_view_register_event_bus
@Test
fun `when take view then register event bus`() {
// given
profilePresenter.takeView(mockView)
// then
then(mockEventBus).should().register(profilePresenter)
}
@igorwojda
igorwojda / PureFunction
Last active October 21, 2017 12:49
Pure function
fun sum(a:Int, b:Int): Int {
return a + b
}
@igorwojda
igorwojda / gist:83a7e5f10a35e5ba452bfbaacb95643e
Created October 21, 2017 13:14
Side effects - modify variable outside the function
fun sum (a:Int, b:Int): Int {
log.info("Added $a + $b")
return a + b
}
@igorwojda
igorwojda / gist:f2490b961ee9c9826082c5dc5c13b216
Created October 21, 2017 13:17
Side effects - modify variable outside function
fun setProgressbarVisibility(visible:Boolean): Int {
progressBar.visible = visible;
}
@igorwojda
igorwojda / gist:00c89fb33c99e3e1c9c17795f8d3b7e0
Created October 21, 2017 13:22
Side effects - retrieving value from outside the function
fun setPatient() {
return this.patient
}
@igorwojda
igorwojda / gist:6e31531c2e03f6242e154b4b2dab0be7
Created October 21, 2017 13:24
Side effects - retrieving value from outside the function
fun getCurrentTime(): Long {
return System.currentTimeMillis()
}
fun getBoolean(): Boolean {
return Random().nextBoolean()
}
@igorwojda
igorwojda / gist:2b5f4621cf55a23a7aa7f7fb1f2d4e9a
Last active October 21, 2017 13:32
Side effects - mutate argument
fun increatePatientAge(patient:Patient): Patient {
patient.age = patient.age++
return patient
}
fun sum (a:Int, b:Int): Int {
if(a > b) {
throw IllegalAccessException()
}
return a + b
}