Can Value Objects create their own value?
Yes, it's not unusual to do that, especially with compound values that need to be backwards compatible with earlier models.
public function generateUsername(UserRepository $userRepository): self
$username = $this->generateRandomUsername();
Your is not a proper way for builder pattern in PHP. Here is the example for Builder pattern in PHP,
* The Builder interface specifies methods for creating the different parts of
* the Product objects.
public function producePartA(): void;
public function ...
The Other Builder Pattern
First, let me just briefly mention that there's a different pattern under the same name: Joshua Bloch's Builder pattern described in Effective Java (see the excerpt here). This pattern was inspired by the GoF Builder pattern; however, it's purpose/intent is not the same - it solves a different problem, so, despite what that ...
I think it's more intuitive to name areas by function first. For example
There are two main reasons, one it doesn't require the observer to know that the workspace feature is implemented on a filesystem. Two, it tends to remain this way longer, ...
direct object creation,
With direct object creation we have client code directly invoking some class constructors via new. This creates a strong coupling between client code and the created classes. Using the client with other classes means editing code of the client (cloning and ...
The Liskov Substitution Principle (LSP) requires that all the child could be used interchangeably with their parents.
This means concretely that the child must work with the tests prepared for the parents. So if you have any pre-conditions for your parents, the child shall not strengthen them. Conversely, the child cannot weaken the post-conditions of ...
No. You need a declared transaction for a rollback to work. Declaring a transaction is necessary so that the original state of the data can be held somewhere. Otherwise, there is nothing to roll back to.
You can easily test this yourself, with and without a transaction, by observing that calling rollback without a transaction has no effect.
It may be ...
What if I want just any grandchild classes inheriting from child(derived in code) class not have public properties of grandfather class($hideme in baseclass)?
If you were able to change the visibility of a member of the base class, such that it would be less visible in the derived type...
Then, the grandchild class would NOT be usable as a replacement of ...
I would simply produce multiline output into one string variable, and then strip whitespace from the multiline output and put the result into another string variable. If the stripped output is greater than your maximum line length, out() returns the multiline output. Otherwise, it returns the stripped output.