plunz
plunz

Reputation: 167

What is the name of the concept which distinguishes static and instance attributes

The concept of public and private variables is called visibility.

I'm looking for a concise word that describes the difference between static attributes and instance attributes. Is scope fitting?

Upvotes: 4

Views: 67

Answers (1)

Borys Serebrov
Borys Serebrov

Reputation: 16172

I think that "ownership" or "relationship" fits better, also the meaning can be somewhat different in different languages.

For example, in Python there are three types of such ownership:

  • Instance attribute / method - belongs to the instance (or the instance owns it)
  • Class method - belongs to the class (the class owns the attribute or method, here we can treat the class itself as an instance of higher-level class)
  • Static attribute / method - logically related to the class, here the class name is used as a namespace

In C++ instance attributes / methods are owned by the instance and static attributes are logically related to the class. We just use the class name as an additional namespace to refer to the static attributes or methods.

In php static attributes are similar to C++, but there is also is also late static binding which affects how static methods work with inheritance. So it depends on the usage - static methods are either just "related" to the class or "owned" by the class (when the late static binding is used).

Regarding the "scope" term - I think it doesn't fit because it is used to describe how the compiler / interpreter finds the meaning of the specific name in the specific context. For example, if you have global variable x and local with same name inside the function, the scope defines which of these two variables will be used.

Upvotes: 1

Related Questions