PHP 5.4 introduced the concept of traits. Until Traits PHP used a classical inheritance model in which one class could inherit only one class. In simple terms; before PHP 5.4 PHP used the single inheritance model which made it difficult to reuse the code.
Traits allow developers to reuse sets of methods freely in several independent classes living in different class hierarchies.
Traits are a mechanism for code reuse in single inheritance languages such as PHP. A Trait 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 of Traits and classes is defined in a way which reduces complexity, and avoids the typical problems associated with multiple inheritance and Mixins.
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 a Trait 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.
Check out PHP.net for more info.
Tuesday, 18 August 2015
Subscribe to:
Post Comments (Atom)
Mastering Frontend Interviews: 10 Essential Concepts Every Developer Should Know
Frontend development interviews can be daunting, particularly with the breadth of topics covered. From JavaScript fundamentals to performanc...
-
"I'm a Celebrity, Get Me Out of Here" has become a cultural phenomenon, captivating audiences worldwide with its thri...
-
The Concept of True North in Lean Methodology In the world of Lean methodology, one of the most fundamental and guiding principles is ...
-
In today's fast-paced digital landscape, ensuring the seamless operation of online services during high-demand events is paramount. The...
No comments:
Post a Comment