Content deleted Content added
Kevin Rector (talk | contribs) mNo edit summary |
mNo edit summary |
||
Line 2:
In [[computer science]], a '''method''' is a [[subroutine|function or subroutine]] that is associated with a [[class (computer science)|class]] in [[object-oriented programming]]. Like a function in procedural languages, it may contain a set of program statements that perform an action, and (in most [[computer language]]s) can take a set of input arguments and can return some kind of result. The purpose of a method is to provide a mechanism for changing or accessing information stored in an [[object (computer science)|object]] of the class.
A method should preserve [[invariant]]s associated with the class, and should be able to assume that every invariant is valid on entry to the method. A method signature can have [[parameter]]s, which are associated with [[precondition]]s. A method may produce output, which are constrained by [[postcondition]]s of the method. If the [[argument]]s to a method do not satisfy their preconditions, a method can raise an [[exception]]. However, if the object's state doesn't satisfy its invariants on entry to the method, or when the method returns, the program is considered to have a [[Software bug|bug]].
Whereas a [[C programming language|C]] [[programmer]] might push a value onto a [[stack_(software)|Stack]] data-structure by calling:
|