Comments (6)
Currently Tag / AttributesTrait are designed as immutable, so all the setters create copies. Nowadays I call such setters not setSomething(), but withSomething(), or withAddedSomething(). E.g. $car->withColor('blue')
.
Calling such methods always has a tiny little overhead.
Within a constructor or when an object is being freshly created, the immutable aspect is not really needed. I would prefer to not create object copies for no reason.
Maybe we should have a static method Tag::createWithAttributes($tagName, $attributes)
? Or add this as an optional parameter to Tag::__construct()
?
One difficulty with static method constructors is always that they need to call new static
or new self
, so they might break in a subclass, if the subclass has a different constructor signature. I already kinda dislike AttributesTrait::create() for this reason.
from cellbrush.
[The usage of PHP Traits is quite confusing, isn't it?]
Yes, I use them a lot less nowadays. They do not properly encapsulate anything, and make it really hard for an IDE to figure out what's going on. I wish PHP had real multiple inheritance.
from cellbrush.
Is this not covered by any test, I wonder?
from cellbrush.
Or maybe a good design for immutable classes is to have a base class with protected mutable setters, and then a subclass which is immutable because it only calls those setters during construction?
from cellbrush.
https://twitter.com/brain4lunch/status/786526053640482817 :)
from cellbrush.
"Or add this as an optional parameter to Tag::__construct()"
This solution seems elegant.
from cellbrush.
Related Issues (9)
- Error after last update HOT 26
- Got an error when trying to use test file HOT 1
- Generating a dynamic table from a data set HOT 22
- How can i use it with Laravel(Installation) HOT 1
- Me too error
- No feature for adding `id` attribute to a table yet. How? HOT 7
- rowspan / colspan in README broken on packagist
- How can I add table attributes? HOT 2
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 cellbrush.