int $id, public readonly string $familyName, public readonly string $givenName, public readonly EmailAddress $email, public readonly DateTime $birthday, public readonly string $postcode, public readonly Prefecture $prefecture, public readonly string $city, public readonly string $street, public readonly string $room, public readonly PhoneNumber $tel, public readonly bool $isActive, ...
public int $id, public string $familyName, public string $givenName, public EmailAddress $email, public DateTime $birthday, public string $postcode, public Prefecture $prefecture, public string $city, public string $street, public string $room, public PhoneNumber $tel, public bool $isActive, ...
public string $name, public int $price, ) { } } final class ItemRecord extends Model { // 略 } $record = ItemRecord::find(id: 17); $item = new Item( id: $record->id, price: $record->price, ); ORM からの変換
CacheRepository $cache; public function _construct() { $this->cache = Cache::store('array'); } public function getSomething(int $arg): int { return $this->cache->remenber($arg, 86400, function (int $arg): int { // 引数に対応して何かを計算して返す処理 return $arg ** 2; }); } } 解決策①:素直にフレームワークに頼る
// 略 public function getSomething(int $arg): int { return $this->cache->getOrElse($arg, function (int $arg): int { // 引数に対応して何かを計算して返す処理 return $arg ** 2; }); } } 解決策②:キャッシュ専⽤のクラスを⽤意する
val a = Point(x = 3, y = 5) val b = a.copy(y = 7) // Kotlin: data class data class Point(val x: Int, val y: Int) val a = Point(x = 3, y = 5) val b = a.copy(y = 7) // Java 16 以降: Record public record Point(int x, int y) {} 他の⾔語の場合
Cloneable; public function __construct( public string $name, public int $price, public Carbon $createdAt, public Carbon $updatedAt, ) { } public function withPrice(int $price): self { return $this->with(price: $price, updatedAt: Carbon::now()); } }