Method (computer programming): Difference between revisions

Content deleted Content added
Danakil (talk | contribs)
No edit summary
Danakil (talk | contribs)
No edit summary
Line 1:
AUsed mainly in [[object-oriented programming]], the term '''method''' isrefers to a [[subprogram (programming)|piece of code]] that, in [[object-oriented programming]], is exclusively associated either with a [[class (computer science)|class]] (called '''class methods''') or with an [[object (computer science)|object]] (called '''instane methods'''). Like a procedure in procedural languages, it usually consists of a sequence of [[statement (programming)|statement]]s to perform an action, a set of input [[argument (programming)|argument]]s to parameterize those actions, and possibly a 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.
 
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]].