terminology of Class “attribute” vs “member” vs “v

2019-04-18 16:49发布

问题:

It seems that developers often use these terms interchangeably when referring to a piece of data stored in an instance of a Class. Is there any technical difference between each term, or is it fine to use them interchangeably?

回答1:

"member" is broader term. It refers everything in that class (instance methods/variables etc.,)

"attribute/variable/field" are same and "member" can be used too.



回答2:

Member : Normally used to define the variables and methods.

Attribute : Attributes are the instance variables of an Object.

Variable : Primitive variables and Objects reference variables as instance or local variables.

Field: Field marks an instance variable.



回答3:

Based on the variety of answers, Class "attributes", "fields", and "variables" are used relatively interchangeably but have nuanced distinctions that vary from person to person. As such, probably best to lump them together and not rely on the nuances.

There's consensus that a Class "member" includes methods as well as data, so it is distinct from the others.



回答4:

Attribute: abstract notion of a property within a class. For instance, a Person class might have a lastName attribute. Usage of attribute vs field can depend on how "complex" the attribute's type is. Simpler types are often referred to as attributes.

Member: this refers to a method or variable that is tied to an object instance

Variable: An abstract concept indicating that the given name represents a value that can vary, and can often be altered

Field: a field is like an attribute, although field is sometimes used to connote something more complex than an attribute.



回答5:

The general usage I've seen:

attribute - pretty much the standard English dictionary meaning. Generally used for more abstract concepts, like Java (bean) properties rather than members, variables, or fields.

member - Methods and fields visible outside the program. In C# includes properties and events.

variable - usually local variables. Sometimes refers to fields, especially when trying to define fields.

fields - class and instance variables; variables visible throughout the class.

(I try to use the words this way myself, so if I've got it wrong let me know!)