- インターフェースをドメインサービスとして作る
- インフラストラクチャ層で実装する
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
const P = require("P"); | |
class A extends P { | |
} |
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
use strict; | |
use warnings; | |
use Data::Dumper; | |
my @vals = ( | |
[1, 2], | |
[3, 4] | |
); | |
my @mapped = map {join("-", @$_)} @vals; |
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 scala.util.Try | |
import scala.language.reflectiveCalls | |
trait Validator[T] { | |
def apply[O <: T](obj: O): Try[O] | |
} | |
type Username = String | |
object UsernameSpecification { |
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
sealed trait T | |
class A extends T { | |
def f:String = "A" | |
} | |
class B extends T { | |
def g:String = "B" | |
} | |
val a = new A | |
val b = new B |
「カーディナリティが高いカラム両方がwhereとorder byに入る場合は、どのようなインデックスを張るべきなんだろうか。」に対する答え。MySQLの場合。
まず、前提として、インデックスの仕組み。インデックスは B+Tree になってて、各ノードにindexに使われてるキーの値、リーフには(indexに使われてるキー,プライマリーキー)の値が書き込まれている。プライマリーキーは例外的に、リーフにその行のすべてのデータが書き込まれているクラスタインデックスになっている。
というわけで、例えば SELECT * FROM t WHERE indexed_column > x;
みたいなクエリを実行すると、
- インデックスツリーからxより大きい値を探して(B+Tree なのでO(log n))
- 探してきた分だけ以下の操作を繰り返す
- リーフに書き込まれてるプライマリーキーの値を読んで
- プライマリキーインデックスを辿って(おなじくO(log n))、リーフに書き込まれているデータを返す
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
module SerializeForSomeMiddleware | |
module Nyan | |
def serialize_for_middleware | |
# Nyanは aの情報だけでよし | |
{a: @a} | |
end | |
end | |
module Wan | |
def serialize_for_middleware | |
# Wanは b も必要 |
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
module SerializeForSomeMiddleware | |
module Nyan | |
def serialize_for_middleware | |
# Nyanは aの情報だけでよし | |
{a: @a} | |
end | |
end | |
module Wan | |
def serialize_for_middleware | |
# Wanは b も必要 |
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
module SerializeForSomeMiddleware | |
module Nyan | |
def serialize_for_middleware | |
# Nyanは aの情報だけでよし | |
{a: @a} | |
end | |
end | |
module Wan | |
def serialize_for_middleware | |
# Wanは b も必要 |
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
module UserValidator | |
module AdministratorContext | |
def validate! | |
raise "name required" if @name.nil? | |
end | |
end | |
module UserContext | |
def validate! | |
end |