Attribute (computing)
Encyclopedia
In computing
Computing
Computing is usually defined as the activity of using and improving computer hardware and software. It is the computer-specific part of information technology...

, an attribute is a specification that defines a property of an object, element, or file. It may also refer to or set the specific value for a given instance of such.

However, in actual usage, the term attribute can and is often treated as equivalent to a property depending on the technology being discussed.

For clarity, attributes should more correctly be considered metadata
Metadata
The term metadata is an ambiguous term which is used for two fundamentally different concepts . Although the expression "data about data" is often used, it does not apply to both in the same way. Structural metadata, the design and specification of data structures, cannot be about data, because at...

. An attribute is frequently and generally a property of a property.

C#

In the C# programming language, attributes are metadata
Metadata
The term metadata is an ambiguous term which is used for two fundamentally different concepts . Although the expression "data about data" is often used, it does not apply to both in the same way. Structural metadata, the design and specification of data structures, cannot be about data, because at...

 attached to a field or a block of code like assemblies
Assembly (programming)
An assembly is a runtime unit consisting of types and other resources. All types in an assembly have the same version number.Often, one assembly has only one namespace and is used by one program. But it can span over several namespaces. Also, one namespace can spread over several assemblies...

, members
Member variable
In object-oriented programming, a member variable is a variable that is associated with a specific class, and accessible for all its methods. If there is only one copy of the variable shared with all instances of the class, it is called a class variable or static member variable...

 and types
Data type
In computer programming, a data type is a classification identifying one of various types of data, such as floating-point, integer, or Boolean, that determines the possible values for that type; the operations that can be done on values of that type; the meaning of the data; and the way values of...

, and are equivalent to annotations in Java
Java annotation
An annotation, in the Java computer programming language, is a special form of syntactic metadata that can be added to Java source code. Classes, methods, variables, parameters and packages may be annotated...

. Attributes are accessible to both the compiler and programmatically through reflection.

Users of the language see many examples where attributes are used to address cross-cutting concerns and other mechanistic or platform uses. This creates the false impression that this is their sole intended purpose. With attributes, it is possible to extend attributes such as , , or .

Their specific use as metadata is left to the developer and can cover a wide range of types of information about any given application, classes and members that is not instance-specific. The decision to expose any given attribute as a property is also left to the developer as is the decision to use them as part of a larger application framework.

Attributes are implemented as classes that are derived from . They are often used by the CLR
Common Language Runtime
The Common Language Runtime is the virtual machine component of Microsoft's .NET framework and is responsible for managing the execution of .NET programs. In a process known as just-in-time compilation, the CLR compiles the intermediate language code known as CIL into the machine instructions...

 services, like COM
Component Object Model
Component Object Model is a binary-interface standard for software componentry introduced by Microsoft in 1993. It is used to enable interprocess communication and dynamic object creation in a large range of programming languages...

 interoperability, remoting, serialisation and can be queried at runtime.

The example shows how attributes are defined in C#:

[Obsolete("Use class C1 instead", IsError = true)] // causes compiler message saying
public class C {...} // that C is obsolete

public class ObsoleteAttribute: Attribute { // class name ends with "Attribute"
public string Message{ get; } // but can be used as "Obsolete"
public bool IsError{ get; set; }
public ObsoleteAttribute {...}
public ObsoleteAttribute(string msg) {...}
public ObsoleteAttribute(string msg, bool error) {...}}
[Obsolete]
[Obsolete("This is obsolete")]
[Obsolete("This is obsolete", false)]
[Obsolete("This is obsolete", IsError = false)]


Positional parameters like first parameter of type string above are parameters of the attribute's constructor. Name parameters like the Boolean parameter in the example are a property of the attribute and should be a constant value.

Attributes should be contrasted against XML documentation that also defines metadata, but is not included in the compiled assembly and therefore cannot be accessed programmatically.

Multi-valued databases

On many post-relational or multi-valued databases systems, relative to SQL, tables are files, rows are items, and columns are attributes. Both in the database and code, attribute is synonymous with property and variable although attributes can be further defined to contain values and subvalues.

The first of these databases was the Pick operating system
Pick operating system
The Pick operating system is a demand-paged, multiuser, virtual memory, time-sharing operating system based around a unique "multivalued" database. Pick is used primarily for business data processing...

. Two current platforms include Rocket U2’s Universe and InterSystems’ Caché
InterSystems
InterSystems Corporation is a privately held vendor of software for high-performance database management, rapid application development, integration, and healthcare information systems...

.

XML

A good example is the process of XML
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....

 assigning values to properties (elements). Note that the element's value is found before the (separate) end tag, not in the element itself. The element itself may have a number of attributes set (NAME = "IAMAPROPERTY").

If the element in question could be considered a property (CUSTOMER_NAME) of another entity (let's say CUSTOMER), the element can have zero or more attributes (properties) of its own (CUSTOMER_NAME is of TYPE = "KINDOFTEXT").

An attribute of an object usually consists of a name and a value; of an element, a type or class name; of a file, a name and extension.
  • Each named attribute has an associated set of rules called operations: one doesn't add characters or manipulate and process an integer
    Integer
    The integers are formed by the natural numbers together with the negatives of the non-zero natural numbers .They are known as Positive and Negative Integers respectively...

     array as an image object— one doesn't process text as type floating point (decimal numbers).

  • It follows that an object definition can be extended by imposing data typing
    Data type
    In computer programming, a data type is a classification identifying one of various types of data, such as floating-point, integer, or Boolean, that determines the possible values for that type; the operations that can be done on values of that type; the meaning of the data; and the way values of...

    : a representation format, a default value, and legal operations (rules) and restrictions ("Division by zero is not to be tolerated!") are all potentially involved in defining an attribute, or conversely, may be spoken of as attributes of that object's type. A JPEG file is not decoded by the same operations (however similar they may be—these are all graphics data formats) as a PNG or BMP file, nor is a floating point typed number operated upon by the rules applied to typed long integers.


For example, in computer graphics
Computer graphics
Computer graphics are graphics created using computers and, more generally, the representation and manipulation of image data by a computer with help from specialized software and hardware....

, line objects can have attributes such as thickness (with real values), color (with descriptive values such as brown or green or values defined in a certain color model, such as RGB
RGB color model
The RGB color model is an additive color model in which red, green, and blue light is added together in various ways to reproduce a broad array of colors...

), dashing attributes, etc. A circle object can be defined in similar attributes plus an origin
Origin (mathematics)
In mathematics, the origin of a Euclidean space is a special point, usually denoted by the letter O, used as a fixed point of reference for the geometry of the surrounding space. In a Cartesian coordinate system, the origin is the point where the axes of the system intersect...

 and radius
Radius
In classical geometry, a radius of a circle or sphere is any line segment from its center to its perimeter. By extension, the radius of a circle or sphere is the length of any such segment, which is half the diameter. If the object does not have an obvious center, the term may refer to its...

.

Markup languages, such as HTML
HTML
HyperText Markup Language is the predominant markup language for web pages. HTML elements are the basic building-blocks of webpages....

 and XML
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....

, use attributes to describe data and the formatting of data.

See also

  • Attributes in HTML
  • File attribute
    File attribute
    A file attribute is metadata that describes or is associated with a computer file. For example, an operating system often keeps track of the date a file was created and last modified, as well as the file's size and extension . File permissions are also kept track of...

  • Extended file attributes
    Extended file attributes
    Extended file attributes is a file system feature that enables users to associate computer files with metadata not interpreted by the filesystem, whereas regular attributes have a purpose strictly defined by the filesystem...

  • Field (computer science)
    Field (computer science)
    In computer science, data that has several parts can be divided into fields. Relational databases arrange data as sets of database records, also called rows. Each record consists of several fields; the fields of all records form the columns....

  • Java annotation
    Java annotation
    An annotation, in the Java computer programming language, is a special form of syntactic metadata that can be added to Java source code. Classes, methods, variables, parameters and packages may be annotated...

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK