Giter VIP home page Giter VIP logo

Comments (1)

TheGeekyM avatar TheGeekyM commented on July 19, 2024

Disagreed with this.

Traits are a form of inheritance, so whatever behavior your trait(s) supply should be thought of as attached to the model itself. So this is really the same thing as the model having this method directly.

Magic accessors are a performance issue, and they make for an exceptionally confusing API. Why? Because nowhere on your model or your database will you find a property called "fullName". If you don't know what it's implemented as a magic accessor, you'll be tearing your hair out wondering where the fuck $user->fullname is coming from. It also kills IDE support, AND kills the ability to define interfaces.

Traits which depend on properties of their children inherently couple them to their children, but do not provide a sane mechanism for requiring that their children have that behavior present. Abstract classes exist because they can define a "relationship contract" whereby their children MUST implement methods that they (the abstract class) rely on (e.g. for the template method pattern). But traits have no such mechanism. This means that splitting code out of a class and into a trait is splitting code for the sake of splitting it, and not merely to better encapsulate responsibility.

A better way to handle presenters is via a decorator or a simple formatting class.

$user = new UserPresenter($user);
$user->getFullName();
or

UserPresenter::getFullName($user);

from presenter.

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.