Attribute (object)

from Wikipedia, the free encyclopedia

An attribute (from Latin attribuere , “assign”, “assign”), also called a property , is generally considered to be a characteristic , identifier, information detail , etc. that is assigned to a specific object . A distinction is made between the meaning (e.g. eye color) and the specific expression (e.g. blue) of the attribute.

In computer science , attribute is understood to mean the level of definition for these characteristics. As such, they are analytically determined, defined and described and, for a certain type of object , defined as elements of its structure (“ modeled ”). Data about the objects are saved in this structure and only with their content, the attribute values. Each object thus represents itself through the entirety of its attribute values.

Each attribute is assigned rules called operations . It follows that an object definition can be extended by defining data types . A display format, a standard value as well as valid operations and restrictions (e.g. division by zero is not permitted) can be involved in the definition of attributes or, conversely, can be referred to as an attribute of the object type .

In computer graphics, for example, line objects can have attributes such as start point and end point (with coordinates as values), width (with a floating point number as value), color (with descriptive values ​​such as red, yellow, green or blue or values ​​defined in a specific color model such as in the RGB color space ) etc. and circle objects can also be defined with the attributes center point and radius .


To process the data, attributes and attribute values ​​can be used in a quantity-restricting manner:

  • for selection : selection of an object subset via its attribute values; E.g .: date of birth <1.1.2000
  • for projection : Only certain attributes should be read / processed for the selected objects; E.g .: only surname, first name, date of birth

C #

In the C # programming language , attributes are metadata attached to a field or block of code such as assemblies, public variables, and data types , and correspond to annotation in Java . Attributes are accessible both to the compiler and programmatically through reflection . With access modifiers like abstract , sealed or public it is possible to extend attributes.

Their specific use as metadata is up to the developer and can cover a variety of types of information about particular applications, classes, and public variables that are not instance specific. The decision to make a particular attribute available as a property is left to the developer as well as the decision to use it as part of a larger application framework.

Attributes are implemented as classes that derive from System.Attribute . They are often used by the CLR - services used for. B. COM - interoperability , remote procedure calls , serialization and can be queried at runtime .

Positional parameters like the first parameter of the 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 with the XML documentation, which also defines metadata , but is not included in the compiled assembly and therefore cannot be accessed programmatically.


The following example in the C # programming language shows the classes , and , which declare public attributes. Most of these attributes of other objects read out but not changed, because the - method with the access modifier declares is. The attribute of the class and the attribute of the class can also be changed by other objects. ParteiAbgeordneterParlamentset private mitgliedsbeitragParteimaximalGroesseParlament

The data types of attributes can be elementary data types or classes , i.e. object types. Most of the attributes in the example have elementary data types. The attribute of vorsitzenderthe class Abgeordneterhas the object type Abgeordneter. The attribute of mitgliederthe class Parteihas the generic type List<Person> , i.e. it is a list with the type parameter Person.

class Person
    public string vorname { get; private set; }
    public string nachname { get; private set; }
    public Date geburtsdatum { get; private set; }
    public List<string> nationalitäten { get; private set; }
    public string MailAdresse { get; private set; }
    public string Postanschrift { get; private set; }

class Partei
	public List<Person> mitglieder { get; private set; }
    public double mitgliedsbeitrag { get; set; }

class Abgeordneter : Person
    public Partei partei { get; private set; }

class Parlament
	public List<Abgeordneter> abgeordnete { get; private set; }
    public Abgeordneter vorsitzender { get; private set; }
    public int maximalGroesse { get; set; }

See also

Individual evidence

  1. ^ Hanspeter Mössenböck, University of Linz: C # Tutorial