Skip to content

Instantly share code, notes, and snippets.

View j-didi's full-sized avatar
🏠
Working from home

Jefferson Didi Silva j-didi

🏠
Working from home
View GitHub Profile
@j-didi
j-didi / Colleague.cs
Created November 14, 2020 20:44
Mediator C# Implementation
// Colleague only exposes Notify method
// SetMediator and HandleNotification are private and protected to simplify client interface
// Not public methods are invoked using reflection.
public abstract class Colleague
{
private IMediator _mediator;
protected void SetMediator(IMediator mediator)
@j-didi
j-didi / Main.kt
Last active June 11, 2020 21:23
Kotlin Domain Specific Language using reflections, infix and aggregation
import com.google.gson.GsonBuilder
import kotlin.reflect.KMutableProperty
import kotlin.reflect.full.memberProperties
//Enum and properties to better infix semantic
private const val Terminal = 0
enum class LogTarget(val value: Int) {
TERMINAL(0);
@j-didi
j-didi / Main.kt
Last active June 10, 2020 22:50
Using generics constrains to manipulate base class properties
import java.time.LocalDateTime
import java.util.UUID.randomUUID
abstract class EntityBase {
lateinit var id: String
lateinit var createAt: LocalDateTime
lateinit var lastUpdateAt: LocalDateTime
}
class Person(val name: String) : EntityBase()
@j-didi
j-didi / Main.kt
Last active June 9, 2020 23:10
Kotlin ValueObject by delegated properties
import java.security.InvalidParameterException
import java.util.regex.Matcher
import java.util.regex.Pattern
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
//Domain entities with E-mail property
class Client(email: String) {
val email: String by EmailDelegated(email)
}
@j-didi
j-didi / Main.kt
Last active June 9, 2020 21:25
Kotlin simple functions delegate implementation example
import java.time.LocalDate
//Domain entity, command an result from CQRS
data class Person(val id: Int, val name: String, val createdAt: LocalDate, val updateAt: LocalDate)
data class PersonCommand(val name: String)
data class PersonResult(val id: Int, val name: String)
//Repository, Logger and Mapper abstractions
interface Repository<T> { fun insert(entity: T) : T }