Difference between property and attribute

Source: Internet
Author: User

Property refers to the data area provided by the class.
Attribute describes the attributes of an object during compilation or runtime. It can be divided into inherent and user-defined attributes. the user-defined attributes can be obtained at runtime Using Reflection.
The two are essentially different.

In the document, either of them is a service attribute, and the other is an interface.

The first type seems to be more accurate. The summary is as follows:

In the minds of many people, attribute is the attribute of the class. What about property? Is it also a class attribute? Therefore, many people do not add a category attribute, especially when writing Chinese articles. This kind of mentality is a typical ostrich mentality, and it is invisible. As a matter of fact, you can just think about it. This is definitely not the case. Since these two terms have been invented in UML, they are obviously not used for redundancy. They must be closely related to each other.

Various object-oriented languages, various component technologies, template technologies, and Web Service technologies, most of which involve the concept of "attribute, in English, attribute, property, or field is often used. Many people call it "attribute", and some places can be differentiated, but some places are just a thousand miles away. I am also worried about these disturbing technologies and terms, but we can at least find a reference standard through the interpretation of these two terms in UML. In any case, UML is a collection of object-oriented technologies and a de facto standard.

Objectively speaking, uml1.4 does not have a clear definition of the two terms, but the difference is still obvious. Attribute should be the darling of uml1.4, and property is not even used in a separate term. No one expected a sudden change in uml2.0, attribute disappears from the class diagram, and property becomes the master.

1. In 4, attribute is a term associated with classifier, which has a smaller impact scope than property. Class is a subclass of classifier, so attribute can also represent the attributes of the class. From the above definition, we can also see that attribute can be the slot named by the classifier instance. For a class, its instance is an object, and the object slot is the object's attribute value slot. Therefore, attribute can be used as an object attribute. Property does not seem to have the meaning of this layer. Based on MOF (another specification of object meta-facility and OMG, which will be explained in detail later), the model layers involved by attribute are from m2 to M0, property seems to be a concept of the M2 layer.

2. Attribute in 0 refers only to the structural features of a class element. You can associate the class Element instance with one or more specific values. The instance slot is not mentioned. I guess this is because the attribute has been used as a subset of the property in uml2.0, so the specific assignment methods for instance slots and so on are as follows, all are explained in the definition of property.

It is also worth noting that attribute is defined in the glossary and does not appear in the metabase diagram. Property appears in the meta-model diagram and is explained in detail. This can be seen that UML strengthens property and weakens the determination of attribute.

Summary of attribute and property

This section summarizes attribute and property based on the latest uml2.0 specifications:

1) In general, attribute is a subset of property, and property is represented as attribute at an appropriate time;

2) property appears in the meta-model of the class graph, representing all the structural features of the class. attribute does not appear in the meta-model and only exists in the concept of class, no corresponding syntax;

3) property has detailed definitions and constraints, but attribute does not have a detailed definition. Therefore, you cannot use OCL to write the constraints.

4) both property and attribute are the concept of M2 layer. On the M1 layer, their instances are the attributes of specific classes; on the m0 layer, their instance instances are the values stored in the slot of specific objects.

 

Property and attribute are both called "attributes" because of negligence in the translation field of domestic IT books.

In fact, they come from two different fields. attribute belongs to the concept of OOA/OOD, and property belongs to the concept of programming language. Below we will illustrate their similarities and differences. AttributeAttributes is the metadata of the Microsoft. NET Framework file. It can be used to describe your code to the runtime, or affect the behavior of the application when the program is running. PropertyAttribute is the basic concept of object-oriented programming. It provides access encapsulation for private fields. In C #, The get and set accessors are used to perform operations on readable and writable attributes, provides secure and flexible data access encapsulation. The concept of attributes is not the focus of this article, and we believe that most technical staff should have a clear concept of attributes. The following are simple differences between attributes. We can say that the two are not comparable, but the differences are only caused by the language characteristics of our country. In fact, as long as we remember that attribute is derived from the system and attribute classes, its main function is to describe, for example DescriptionA method is a DLL from external sources. You can write the following code. This is an attribute, which is a description (or declaration) [dllimport ("user32.dll")]. attribute also has many system "default" attributes, as shown in the following table.
Predefined attributes Effective Target Description
Attributeusage Class Specify the valid usage of another attribute class
Clscompliant All Indicates whether the program element is compatible with Cls.
Conditional Method Indicates that if no associated string is defined, the compiler can ignore any call to this method.
Dllimport Method Specifies the DLL location that contains the implementation of external Methods
Stathread Method (main) Indicates that the default thread model of the program is Sta.
Mtathread Method (main) Specifies that the default program model is multi-thread (MTA)
Obsolete Besides assembly, module, parameter, and return Mark an element as unavailable, notifying users that this element will be used by future products
Paramarray Parameter Allows a single parameter to be treated implicitly as a Params (array) parameter
Serializable Class, struct, Enum, delegate All public and private fields of this type can be serialized.
Nonserialized Field Applies to Fields marked as serializable classes, indicating that these fields cannot be serialized
Structlayout Class, struct Specifies the nature of the data layout of a class or structure, such as auto, explicit, or sequential
Threadstatic Field (static) Implement local thread storage (TLS ). A given static field cannot be shared across multiple threads. Each thread has a copy of this static field.
Property is a field in the programming process, that is, a member of the class. For example:
Private int hour; // defines the private variable to indicate "Hour", which cannot be accessed externally .} public int hour // defines the hour program interface {set {hour = value;} get {return hour ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.