Content deleted Content added
Restored revision 1222233433 by AntiCompositeNumber (talk) |
JohnjPerth (talk | contribs) m for clarity, refer to the preceding examples of variables |
||
Line 108:
OOP languages are diverse, but typically OOP languages allow [[Inheritance (object-oriented programming)|inheritance]] for code reuse and extensibility in the form of either [[class (computer science)|classes]] or [[Prototype-based programming|prototypes]]. These forms of inheritance are significantly different, but analogous terminology is used to define the concepts of ''object'' and ''instance''.
In [[class-based programming]], the most popular style, each object is required to be an [[instance (computer science)|instance]] of a particular ''class''. The class defines the data format or [[data type|type]] (including member variables and their types) and available procedures (class methods or member functions) for a given type or class of object. Objects are created by calling a special type of method in the class known as a [[Constructor (object-oriented programming)|constructor]]. Classes may inherit from other classes, so they are arranged in a hierarchy that represents "is-a-type-of" relationships. For example, class Employee might inherit from class Person. All the data and methods available to the parent class also appear in the child class with the same names. For example, class Person might define variables "first_name" and "last_name" with method "make_full_name()". These will also be available in class Employee, which might add the variables "position" and "salary". It is guaranteed that all instances of class Employee will have the same attributes (variables, not their values), such as the name, position, and salary. Procedures and variables can be specific to either the class or the instance; this leads to the following terms:
* [[Class variable]]s – belong to the ''class as a whole''; there is only one copy of each variable, shared across all instances of the class
* [[Instance variable]]s or attributes – data that belongs to individual ''objects''; every object has its own copy of each one. All 4 variables mentioned above (first_name, position etc) are instance variables.
* [[Member variable]]s – refers to both the class and instance variables that are defined by a particular class.
* Class methods – belong to the ''class as a whole'' and have access to only class variables and inputs from the procedure call
* Instance methods – belong to ''individual objects'', and have access to instance variables for the specific object they are called on, inputs, and class variables
|