Method (computer science)
Used mainly in object-oriented programming, the term method refers to a piece of code that is exclusively associated either with a class (called class methods or static methods) or with an object (called instance methods). Like a procedure in procedural programming languages, a method usually consists of a sequence of statements to perform an action, a set of input parameters to parameterize those actions, and possibly an output value (called return value) of some kind. The purpose of methods is to provide a mechanism for accessing (for both reading and writing) the private data stored in an object or a class.
Related Topics:
Object-oriented programming - Piece of code - Class - Object - Procedural programming languages - Statements - Parameters
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
A method should preserve the class invariants of the object it is associated with, and should always assume that they are valid when it commences execution. To this effect, preconditions are used to constrain the method's parameters, and postconditions to constrain method's output, if it has one. If any one of either the preconditions or postconditions is not met, a method may raise an exception. If the object's state does not satisfy its class invariants on entry to or exit from any method, the program is considered to have a bug.
Related Topics:
Class invariants - Precondition - Postcondition - Exception - Bug
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
The difference between a procedure (usually miscalled a "function") and a method is that the latter, being associated with a particular object, may access or modify the data private to that object in a way consistent with the intended behavior of the object. Consequently, rather than thinking "a method is just a sequence of commands", an OO programmer will consider a method to be "an object's way of providing a service" (its "method of doing the job", hence the name); a method call is thus considered to be a request to an object to perform some task. Method calls are often modelled as a means of passing a message to an object. Rather than pushing a value onto the stack, a value is sent to the stack, along with the message "push!", and the stack either complies or raises an exception describing why it can not do so.
Related Topics:
Service - Task - Message
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~ Table of Content ~
| ► | Introduction |
| ► | Kinds of methods |
| ► | Isolation levels |
| ► | See also |
~ What's Hot ~
~ Community ~
| ► | History Forum Come and discuss about History, Civilizations, Historical Events and Figures |
| ► | History Web-Ring A community of sites, blogs and forums dedicated to History. Do not hesitate to submit your site. |
and are licensed under the GNU Free Documentation License.
Lexicon - Privacy Policy - Spiritus-Temporis.com ©2005.