Difference between revisions of "Class (computer programming)"
From Wiki @ Karl Jones dot com
Karl Jones (Talk | contribs) (→See also) |
Karl Jones (Talk | contribs) |
||
Line 5: | Line 5: | ||
Classes provide: | Classes provide: | ||
− | * Initial values for state ([[member variables]]) | + | * Initial values for state ([[Member variable|member variables]]) |
− | * Implementations of behavior ([[member functions]]). | + | * Implementations of behavior ([[Member function|member functions]]). |
In many languages, the class name is used as the name for the class (the template itself), the name for the [[default constructor]] of the class ([[subroutine]] that creates objects), and as the type of objects generated by the type, and these distinct concepts are easily conflated. | In many languages, the class name is used as the name for the class (the template itself), the name for the [[default constructor]] of the class ([[subroutine]] that creates objects), and as the type of objects generated by the type, and these distinct concepts are easily conflated. | ||
Line 31: | Line 31: | ||
* [[Default constructor]] | * [[Default constructor]] | ||
* [[First-class citizen]] | * [[First-class citizen]] | ||
+ | * [[Member function]] | ||
+ | * [[Member variable]] | ||
* [[Object (computer science)]] | * [[Object (computer science)]] | ||
* [[Object-oriented programming]] | * [[Object-oriented programming]] |
Latest revision as of 08:56, 4 September 2016
In object-oriented programming, a class is an extensible program-code-template for creating objects.
Description
Classes provide:
- Initial values for state (member variables)
- Implementations of behavior (member functions).
In many languages, the class name is used as the name for the class (the template itself), the name for the default constructor of the class (subroutine that creates objects), and as the type of objects generated by the type, and these distinct concepts are easily conflated.
Instance
When an object is created by a constructor of the class, the resulting object is called an instance of the class, and the member variables specific to the object are called instance variables, to contrast with the class variables shared across the class.
Compile-time versus runtime
With respect to compile-time versus runtime, classes differ by language.
- In some languages, classes are only a compile-time feature (new classes cannot be declared at runtime)
- In other languages classes are first-class citizens, and are generally themselves objects (typically of type Class or similar).
- In these languages, a class that creates classes is called a metaclass.
See also
- Compile-time
- Computer program
- Computer programming
- Computer science
- Constructor
- Default constructor
- First-class citizen
- Member function
- Member variable
- Object (computer science)
- Object-oriented programming
- Programming paradigm
- Property (programming)
- Runtime
- Structured programming
- Subroutine
External links
- Class (computer programming) @ Wikipedia