Home >Web Front-end >JS Tutorial >Learn the basic concepts of object-oriented object-oriented: objects and other basic elements_js object-oriented
What is an object
An object is a thing, an entity, a noun. In summary: everything is an object
An object holds certain information and knows how to perform certain operations
State and behavior of objects
Objects have states. The state is a description of one or more attributes of the object (for example: a light "The light is on. This is its state")
Objects have behaviors. Behaviors are the actions and reactions of an object to change its own state (for example: a light "turns off the light" is its behavior)
The most primitive unit among surface-like objects is the object
Packaging
The act of aggregating data and operations that affect this data into an object is called "encapsulation"
Encapsulates the attributes and implementation details of hidden objects, public to public interfaces, and controls the access level for reading and modifying attributes in the program
From the outside view, the data encapsulated in an object is hidden
The purpose of encapsulation is to enhance security and simplify programming. Users do not need to know the specific implementation details, but only need to use the object’s externally developed interface and a specific access permission to use the members of the object
Messages and methods
Message sending
An object accesses another object by sending a "message". Such access, called "message sending", is the only way for an object to access another object
The message sending process includes: sender->Message [name and parameters]->receiver
Message
A "message" consists of the name of an operation and all necessary parameters. When an object sends a message to another object, the sender requests the message receiver to perform the specified operation and (possibly) return Information, when the recipient receives the message, it performs the requested operation in a way it knows how to do. Such a request does not specify how to perform an operation. This information is always hidden from the sender
Message name
A message includes the operation name and all the parameters required by the operation. Sometimes, it is useful to look up the operation by its name, regardless of its parameters. We call the name of an operation "message name" ".
Method
When an object receives a message, it performs a method to complete the requested operation. This "method" is to execute the algorithm step by step. Respond to a received message when the message name and operation name match. As dictated by the information hiding principle. Methods are always part of an object's private representation, not part of a formulaic interface.
Signature
One of the more useful concepts related to message sending is signature. When a message consists of a method and the parameters required by the method, the "signature" is the name of the method, the parameter type and the return object. The type of signature is a formal specification of method input and a formal specification of method output. It specifies what is necessary to use this method