New answers tagged

0

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(); if (!$userRepository->userExist($username)) ...


0

Your is not a proper way for builder pattern in PHP. Here is the example for Builder pattern in PHP, <?php namespace RefactoringGuru\Builder\Conceptual; /** * The Builder interface specifies methods for creating the different parts of * the Product objects. */ interface Builder { public function producePartA(): void; public function ...


4

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 ...


2

I think it's more intuitive to name areas by function first. For example /areas/feature1 /areas/feature1/models /areas/feature1/data-access /areas/workspace /areas/workspace/data-access 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, ...


3

Let's consider: direct object creation, simple factory, factory method, abstract factory 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 ...


4

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 ...


0

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 ...


2

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 ...


1

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.


Top 50 recent answers are included