Giter Site home page Giter Site logo

Comments (3)

peter-gribanov avatar peter-gribanov commented on May 11, 2024

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:

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.

vidic-igor avatar vidic-igor commented on May 11, 2024

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.

peter-gribanov avatar peter-gribanov commented on May 11, 2024

@vidic-igor ClockAwareTrait is just an example of bad practice in using traits.

from clean-code-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.