This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ChangeEmailUseCase @Inject() ( | |
userEmailUniqueChecker: UserEmailUniqueChecker, | |
userRepository: UserRepository | |
) { | |
import ChangeEmailOutput._ | |
override def handle(input: ChangeEmailInput): ChangeEmailOutput = { | |
val result = for { | |
user <- userRepository.findById(input.userId).toRight(NotFoundUser(input.userId)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait UserEmailUniqueChecker extends DomainService { | |
/** | |
* 引数のメールアドレスがユニークであるかどうかを調べる | |
*/ | |
def check(email: EmailAddress): Boolean | |
} | |
final class User private ( | |
val id: UserId, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let mut rect = Rectangle { | |
width: 10, | |
height: 15, | |
}; | |
println!("rectangle area is: {}", rect.area()); | |
// let mut で宣言されたものでないと呼び出せない。 | |
rect.set_width(20); | |
// rect の内部状態が代わり、rect.widthが20になっているので、結果は300になる | |
println!("rectangle area is: {}", rect.area()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {PreferNominal} from "../../prefer-nominal"; | |
import * as E from "fp-ts/Either"; | |
export class EnglishName { | |
// noinspection JSUnusedGlobalSymbols | |
readonly _englishNameBrand: PreferNominal; | |
constructor(readonly value: string) { | |
if (!EnglishName.isValid(value)) { | |
throw new TypeError(this.requirementErrorMessage); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample2 | |
import usecase.create.CreateUserOutput.UserNameConflict | |
import usecase.create.{CreateUserInput, CreateUserOutput, CreateUserUseCase} | |
class CreateUserInteractor( | |
userNameConflictValidator: UserNameConflictValidator, | |
userRepository: UserRepository | |
) extends CreateUserUseCase { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample2 | |
import user.{UserId, UserName, UserNameDuplicateError} | |
/** | |
* ユーザー | |
* | |
* @note デフォルトコンストラクタは `private` にして生成処理を絞っている。 | |
* ADTを利用した状態遷移はインスタンスの生成方法の制御が重要である。 | |
* 型パラメータを自由につけてインスタンスを生成できては、制約の効果がないためだ。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person private (val firstName: String, val lastName: String, val age: Int) | |
object Person { | |
class Builder { | |
var firstName: String = "" | |
var lastName: String = "" | |
var age: Int = 0 | |
private var hasFirstName: Boolean = false | |
private var hasLastName: Boolean = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package first | |
import first.usecase.{CreateUserInput, CreateUserOutput, CreateUserUseCase} | |
final class CreateUserInteractor(userService: UserService, userRepository: UserRepository) extends CreateUserUseCase { | |
override def handle(input: CreateUserInput): CreateUserOutput = { | |
val newUser = User.create(input.name) | |
userService.exists(newUser) match { // このバリデーションが必ず必要だが、知らないとできない。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.rinotc.purchaseSample.models.purchase | |
import com.github.rinotc.purchaseSample.models.money.Money | |
import com.github.rinotc.purchaseSample.models.part.Part | |
import com.github.rinotc.purchaseSample.models.{Aggregate, Entity} | |
import java.util.Currency | |
/** | |
* 購入注文 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person( | |
val firstName: String, | |
val lastName: String, | |
val age: Int | |
) { | |
protected def this() = this("", "", 0) | |
protected def this(pb: Person.Builder[_]) = this(pb.firstName, pb.lastName, pb.age) | |
} | |
object Person { |
NewerOlder