Comments (3)
In example Prefer composition over inheritance EmployeeTaxData
plays the role of ValueObject more than extensions of functionality.
There are no examples of Traits because there are very few normal cases when Traits are really necessary and have an advantage over other implementations.
I know just a few such examples:
- Symfony ContainerAwareTrait for inject Container in any services;
- Aggregates of domain events AggregateEventsTrait and AggregateEventsRaiseInSelfTrait.
These are very specific examples, not everyone understands and not everyone needs. In my opinion, they are too complicated for this guide.
Can you give a simple example that will be really useful, and not Trait for the sake of Trait?
from clean-code-php.
The new Symfony Clock component, has good use case for trait implementation.
Instead of having a dependency injection for each service you want to make "clock aware", you can just extend it by using a trait (ClockAwareTrait).
also all test that are required to be "time senstive" aka. aware of the clock in order for it to be mocked inside test, you don't need to extend the test case with a base class or write it from scratch each time, you can just use a trait (ClockSensitiveTrait) in order to reuse and set the clock for each test that needs it.
from clean-code-php.
@vidic-igor ClockAwareTrait is just an example of bad practice in using traits.
from clean-code-php.
Related Issues (20)
- Change from JS to PHP in "Functions should only be one level of abstraction" HOT 1
- Database Interface Layer concrete example HOT 1
- Need help to understand the Avoid Conditionals section. HOT 2
- Possibly incorrect: "Zero arguments is the ideal case" HOT 4
- Question on coupling of static classes HOT 4
- Comparison text HOT 1
- Discussion about "Don't add unneeded context" HOT 4
- reusable value-objects w/ better type safety HOT 4
- Persian translation
- "Use default arguments instead of short circuiting or conditionals" HOT 2
- Arabic translation HOT 2
- Indonesia translation
- How to handle un/happy paths HOT 6
- An array is a dumb container of unknown data
- Define constants in those methods where you use, not globally
- adding ndonesian translation section + Refactor code under collapsible markdown
- Problem in the fibonacci function
- Book PHp
- Premier jet du dictionnaire de données
- Cleen code
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clean-code-php.