Attribute-oriented programming
Attribute-oriented programming (@OP) is a technique for embedding metadata, namely attributes, within program code.
01Attribute-oriented programming in various languages
C++
C++ has support for attributes. C++11 added attributes, which can indicate extra information to the compiler. C++26 added annotations for reflection.
C#
The C# language has supported attributes from its very first release. These attributes was used to give run-time information and are not used by a preprocessor. Currently with source generators, you can use attributes to drive generation of additional code at compile-time.
Hack
The Hack programming language supports attributes. Attributes can be attached to various program entities, and information about those attributes can be retrieved at run-time via reflection.
Java
Java has support for annotations. With the inclusion of Metadata Facility for Java (JSR-175) into the J2SE 5.0 release it is possible to utilize attribute-oriented programming right out of the box. XDoclet library makes it possible to use attribute-oriented programming approach in earlier versions of Java.
In Java, annotations are used for code generation and reflection.
UML
The Unified Modeling Language (UML) supports a kind of attribute called stereotypes.
02Tools
- Annotation Processing Tool (apt)
- Spoon, an Annotation-Driven Java Program Transformer
- XDoclet, a Javadoc-Driven Program Generator
Sources and credits
This article is adapted from the Wikipedia article “Attribute-oriented programming”, written by its contributors and licensed under CC BY-SA 4.0. Fathomly has changed the layout, removed citation markers, navigation and maintenance notices, and adjusted punctuation. This adapted version is shared under the same license. For references, see the original article.
Fathomly is not affiliated with or endorsed by the Wikimedia Foundation. Spotted a problem? Tell us.