I'm creating projects with Symfony2/Doctrine and try to implement traits. So far no problem on small tryouts, but I usually do UML class and sequence diagrams before deep in complex projects.
What is the UML design object(s) to be used to symbolize PHP traits, which can be seen as far as I know as behaviors? Is ther any clean way to do so?
Thanks a lot for your answers !
Nicolas
UML provides mechanisms to represent class members, such as attributes and methods, and additional information about them like constructors.
A node in UML is represented by a square box as shown in the following figure with a name. A node represents the physical component of the system. Node is used to represent the physical part of a system such as the server, network, etc.
Traits are used to declare methods that can be used in multiple classes. Traits can have methods and abstract methods that can be used in multiple classes, and the methods can have any access modifier (public, private, or protected).
In UML models, attributes represent the information, data, or properties that belong to instances of a classifier. A classifier can have any number of attributes or none at all. Attributes describe a value or a range of values that instances of the classifier can hold.
PHP
Trait
is basically UML Abstract Class or UML Class Template connected to the used-in class with the UML Generalization Relationship utilizing the multiple inheritance notation
See also:
Figure "UML Diagram with a Trait" in article Brendan Bates: Traits: The Right Way
Programmers: Is there a representation for mixins or traits on UML?
PHP Manual → Language Reference → Classes and Objects → Traits
As of
PHP
5.4.0,PHP
implements a method of code reuse calledTraits
.
Traits
are a mechanism for code reuse in single inheritance languages such asPHP
. ATrait
is intended to reduce some limitations of single inheritance by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies. The semantics of the combination ofTraits
and classes is defined in a way which reduces complexity, and avoids the typical problems associated with multiple inheritance andMixins
.A
Trait
is similar to a class, but only intended to group functionality in a fine-grained and consistent way. It is not possible to instantiate aTrait
on its own. It is an addition to traditional inheritance and enables horizontal composition of behavior; that is, the application of class members without requiring inheritance
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With