Home  >  Article  >  Backend Development  >  What is object-oriented

What is object-oriented

肚皮会动
肚皮会动Original
2017-11-14 10:58:471489browse

PHP Object-oriented

In object-oriented programming (English: Object-oriented programming, abbreviation: OOP), an object is a description of information and the processing of information The whole composed is an abstraction of the real world.

In the real world, the things we face are objects, such as computers, televisions, bicycles, etc.

The main three characteristics of the object:

The behavior of the object: What operations can be applied to the object, turning on the light and turning off the light are behaviors.

The shape of the object: how the object responds, color, size, and appearance when those methods are applied.

Representation of objects: The representation of objects is equivalent to an ID card, specifically distinguishing the differences in the same behavior and status.

For example, Animal is an abstract class. We can specify a dog and a sheep, and dogs and sheep are concrete objects. They have color attributes, can be written, can run and other behavioral states. .

Object-oriented content

Class − defines the abstract characteristics of a thing. The definition of a class includes the form of the data and the operations on the data.

Object − is an instance of a class.

Member variables − Variables defined inside the class. The value of this variable is invisible to the outside world, but can be accessed through member functions. After the class is instantiated as an object, the variable can be called an attribute of the object.

Member function − Defined inside the class, it can be used to access the data of the object.

Inheritance − Inheritance is a mechanism for subclasses to automatically share the data structures and methods of parent classes. This is a relationship between classes. When defining and implementing a class, you can do it on the basis of an existing class, take the content defined by the existing class as your own content, and add some new content.

Parent class − A class is inherited by other classes. This class can be called a parent class, a base class, or a super class.

Subclass − A class that inherits other classes is called a subclass, or a derived class.

Polymorphism − Polymorphism means that the same function or method can act on multiple types of objects and obtain different results. Different objects can produce different results when receiving the same message. This phenomenon is called polymorphism.

Overloading − Simply put, it is a situation where functions or methods have the same name but different parameter lists. Such functions or methods with the same name and different parameters are called overloaded functions or methods. .

Abstraction − Abstraction refers to abstracting objects with consistent data structures (attributes) and behaviors (operations) into classes. A class is an abstraction that reflects important properties related to an application while ignoring other irrelevant content. The division of any class is subjective, but must be related to the specific application.

Encapsulation − Encapsulation refers to binding the properties and behavior of an object that exists in the real world together and placing it in a logical unit.

Constructor − Mainly used to initialize the object when creating the object, that is, assigning initial values ​​to the object member variables. It is always used together with the new operator to create the object. in the statement.

Destructor − Destructor (destructor) is the opposite of the constructor, when the object ends its life cycle (for example, the function in which the object is located has been called) , the system automatically executes the destructor. Destructors are often used to do "clean-up" work (for example, when creating an object, use new to open up a memory space, which should be released with delete in the destructor before exiting).

That’s the basic introduction to object-oriented, I hope it will be helpful to you.

Related recommendations:

Analysis of object-oriented questions in php interview questions

JavaScript object-oriented basics and this pointing questions Detailed analysis

Object-oriented implementation of a simple version of Super Mario mini-game

What are object-oriented principles

The above is the detailed content of What is object-oriented. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn