Method (computer programming): Difference between revisions

Content deleted Content added
Importing Wikidata short description: "Computer function or subroutine that is tied to a particular instance or class" (Shortdesc helper)
m Added links, combined short, disjointed sentences into longer ones (no meaning change)
Tags: Mobile edit Mobile app edit iOS app edit
Line 1:
{{short description|Computer function or subroutine that is tied to a particular instance or class}}
A '''method''' in [[object-oriented programming]] (OOP) is a [[Procedure (computer science)|procedure]] associated with a [[Message passing|message]] and an [[Object (computer science)|object]]. An object consists of data and behavior. The data and behavior comprise an interface, which specifies how the object may be utilized by any of various consumers<ref name="consumerdef001a">Consumers of an object may consist of various kinds of elements, such as other programs, remote computer systems, or computer programmers who wish to utilize the object as part of their own programs.</ref> of the object.
 
A '''method''' in [[object-oriented programming]] (OOP) is a [[Procedure (computer science)|procedure]] associated with a [[Message passing|message]] and an [[Object (computer science)|object]]. An object consists of ''data'' and ''behavior.''; The data and behaviorthese comprise an [[Interface (computing)|''interface'']], which specifies how the object may be utilized by any of its various consumers<ref name="consumerdef001a">Consumers of an object may consist of various kinds of elements, such as other programs, remote computer systems, or computer programmers who wish to utilize the object as part of their own programs.</ref> of the object.
Data is represented as [[Property (programming)|properties]] of the object and behaviors are represented as methods of the object. For example, a <code>Window</code> object could have methods such as <code>open</code> and <code>close</code>, while its state (whether it is opened or closed at any given point in time) would be a property.
 
Data is represented as [[Property (programming)|properties]] of the object, and behaviors are represented as methods of the object. For example, a <code>Window</code> object could have methods such as <code>open</code> and <code>close</code>, while its state (whether it is openedopen or closed at any given point in time) would be a property.
In [[class-based programming]], methods are defined in a [[class (computer science)|class]], and objects are instances of a given class. One of the most important capabilities that a method provides is method overriding. The same name (e.g., <code>area</code>) can be used for multiple different kinds of classes. This allows the sending objects to invoke behaviors and to delegate the implementation of those behaviors to the receiving object. A method in Java programming sets the behavior of a class object. For example, an object can send an <code>area</code> message to another object and the appropriate formula is invoked whether the receiving object is a <code>rectangle</code>, <code>circle</code>, <code>triangle</code>, etc.
 
In [[class-based programming]], methods are defined in a [[class (computer science)|class]], and objects are [[Instance (computer science)|instances]] of a given class. One of the most important capabilities that a method provides is ''[[method overriding.]]'' The- the same name (e.g., <code>area</code>) can be used for multiple different kinds of classes. This allows the sending objects to invoke behaviors and to delegate the implementation of those behaviors to the receiving object. A method in [[Java (programming language)|Java]] programming sets the behavior of a class object. For example, an object can send an <code>area</code> message to another object and the appropriate formula is invoked whether the receiving object is a <code>rectangle</code>, <code>circle</code>, <code>triangle</code>, etc.
Methods also provide the interface that other classes use to access and modify the data [[Property (programming)|properties]] of an object. This is known as encapsulation. Encapsulation and overriding are the two primary distinguishing features between methods and procedure calls.<ref>{{cite web|title=What is an Object?|url=http://docs.oracle.com/javase/tutorial/java/concepts/object.html|work=oracle.com|publisher=Oracle Corporation|accessdate=13 December 2013}}</ref>
 
Methods also provide the interface that other classes use to access and modify the data [[Property (programming)|properties]] of an object.; Thisthis is known as [[Encapsulation (computer programming)|''encapsulation'']]. Encapsulation and overriding are the two primary distinguishing features between methods and procedure calls.<ref>{{cite web|title=What is an Object?|url=http://docs.oracle.com/javase/tutorial/java/concepts/object.html|work=oracle.com|publisher=Oracle Corporation|accessdate=13 December 2013}}</ref>
 
==Overriding and overloading==