Answer the question
In order to leave comments, you need to log in
Update immutable Value Object?
VO update?
class UserName {
private string $name;
public function __construct(string $name) {
$this->name = $name;
}
public function update(string $name): self {
$copy = clone $this;
$copy->name = $name;
return $copy;
}
public function update(string $name): self {
$new = new self($name);
$new->name = $name;
return $new;
}
$user->setName($user->name->update('new_name_str'));
...
class User {
public UserName $name;
...
public function setName(UserName $name){
$this->name = $name;
}
...
class User {
...
public function setName(string $name){
$this->name = new UserName($name);
}
...
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question