31

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?

Ola Ström
  • 4,136
  • 5
  • 22
  • 41
Josh Diehl
  • 2,913
  • 2
  • 31
  • 43
  • 2
    http://en.wikipedia.org/wiki/Field_(computer_science) – Nir Alfasi Jul 05 '12 at 18:38
  • 2
    In general you'll see a lot of overlap, especially for programmers who regularly work with multiple languages or technologies who have conflicting terminology for the same concept. Eg. "function" versus "method." – Roddy of the Frozen Peas Jul 05 '12 at 18:42
  • Should probably get this added to this list: http://haacked.com/archive/2006/02/08/OnReligiousWarsinSoftware.aspx – billjamesdev Jul 05 '12 at 18:51
  • Interesting list, but based on the responses here doesn't seem like anyone is super passionate about using one or the other. – Josh Diehl Jul 06 '12 at 18:24
  • In Java 'Member variable', 'Member fields' and 'instance variable' are synonym. These includes all methods and all fields of a class and are associated with a specific class object. Variables inside a method or a block of code are called: 'local variables'. Variables in a method declarations are called: 'parameters'. 'Static variables', 'class variables' are synonym and are common to all objects of this class and not a particular instance. 'Static members' include: 'static variable', 'static methods', 'static blocks' and 'nested classes'. – Java bee Nov 21 '20 at 16:36

5 Answers5

10

"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.

kosa
  • 65,990
  • 13
  • 130
  • 167
  • 5
    Not all variables are attributes. – Joseph Elcid Jul 05 '12 at 18:42
  • @JosephElcid, Can you provide a case? I might mis-understood. – kosa Jul 05 '12 at 18:44
  • In my understanding attributes are visible in some way to the client, while variables can be private and seen only within the class. – namenamename Jul 05 '12 at 18:48
  • @ConorSherman: All these terminologies refer to same thing that one memory location associated with an Object/Class. How we call them differs based on the people programming back-ground. – kosa Jul 05 '12 at 18:52
  • 4
    In `oop` attribute have visibility, variables don't. more [here](http://klsteven.com/pdfs/Variables_vs_Attribute_inspection.pdf) – Joseph Elcid Jul 05 '12 at 18:57
  • @JosephElcid I think the link you provided is irrelevant to this discussion, because there is nothing about visibility, and it starts with "In simple terms attributes control is at the limits, variables control within the limits. Concerning the data that is generated by each concept, attributes data is discreet whereas variables data is continuous.", which is nonsense. Later it continues about industry. – Yaroslav Nikitenko Feb 15 '23 at 14:33
10

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.

Josh Diehl
  • 2,913
  • 2
  • 31
  • 43
9

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.

Kumar Vivek Mitra
  • 33,294
  • 6
  • 48
  • 75
3

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!)

RalphChapin
  • 3,108
  • 16
  • 18
2

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.

ControlAltDel
  • 33,923
  • 10
  • 53
  • 80