A method in object-oriented programming is a function or procedure that belongs to some class or object .
Like a procedure in procedural programming , a method consists of a number of operators for performing an action and has a set of input arguments .
There are simple methods and static methods (class methods):
- simple methods have access to the data of an object (a specific instance of a given class),
- static methods do not have access to object data, and to use them, you do not need to create instances (of this class).
Methods provide an interface through which access to the data of an object of a certain class is carried out, thereby ensuring data encapsulation .
Depending on what level of access this or that method provides, allocate:
- open (
public) interface - a common interface for all users of this class; - protected interface - an internal interface for all descendants of this class;
privateinterface - an interface that is accessible only from within this class.
This separation of interfaces allows you to keep the open interface unchanged, but change the internal implementation.
See also
- Property
- Event