Learning the basic concepts of object-oriented: object and other basic elements _ js object-oriented

Source: Internet
Author: User
Learning the basic concepts of object-oriented: objects and other basic elements What is an object?

An object is a thing, an entity, and a noun. In a word, everything is an object.

An object stores some information and knows how to perform some operations.

Object status and Behavior

An object has a state, and its state is a description of one or more attributes of the object (for example, a light "The light is on, this is its state ")

The action of an object is the action and reaction of the object to change its status (for example, a light turns off the light and this is its action)

The most primitive unit in a face object is an object.

Encapsulation

The behavior of aggregating data and operations that affect this data into an object is called "encapsulation"

Encapsulate and hide the attributes and implementation details of an object, provide public-to-public interfaces, and control the read and modify access levels of attributes in a program.

From the external view, the data encapsulated in an object is hidden.

The purpose of encapsulation is to enhance security and simplify programming. users do not have to understand the specific implementation details. Instead, they only need to use the object's members through the interface developed by the object and the specific access permissions.

Messages and Methods

Message sending

An object accesses another object by sending a "message". Such an access is called "message sending" and 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 an operation name and all required parameters. When an object sends a message to another object, the sender requests the message recipient to perform the specified operation and (possibly) return information. When the receiver receives a message, it performs the requested operation in the way it knows. Such a request does not specify how to perform an operation. This information of the sender is always hidden.

Message name  

A message includes the operation name and all the parameters required by the Operation. Sometimes, it is useful to view the operation by name without considering its parameters, the name of an operation is called "message name ".

Method

When an object receives a message, it executes a method to complete the requested operation. This "method" is to execute the algorithm step by step. The received message is returned when the message name matches the operation name. As specified by the Information Hiding principle. A method is always a part of an object's private expression, not a part of the formula interface.

Signature

A more useful concept related to message sending is signature. When a message is composed of parameters required by a method and method, "signature" is the name of this method, the parameter type and the type of the returned object. The signature is the formal description of the method input and the formal description of the method output. It specifies what is necessary to use this method

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.