Home  >  Article  >  Backend Development  >  What is a class? What is an object? What is the relationship between classes and objects?

What is a class? What is an object? What is the relationship between classes and objects?

怪我咯
怪我咯Original
2017-06-28 13:45:543438browse

Object-oriented(Object Oriented,OO).

Initially, "object-oriented" refers to the use of design methods such as encapsulation, inheritance, and polymorphism in programming. Now, object-oriented thinking has been involved in all aspects of software development. For example, object-oriented analysis (OOA, ObjectOriented Analysis), object-oriented design (OOD, Object Oriented Design), and object-oriented programming implementation (OOP, Object Oriented Programming).

Explanation of objects and classes:

1) Object: An object is anything that people want to study. It can not only represent specific things, but also abstract rules, plans or event. Objects have state, and an object uses data values ​​to describe its state. Objects also have operations, which are used to change the state of the object. The object and its operations are the behavior of the object. Objects realize the combination of data and operations, so that data and operations are encapsulated in the unity of objects.

2) Class: The abstraction of objects with the same characteristics (data elements) and behavior (function) is a class. Therefore, the abstraction of an object is a class, and the concretization of a class is an object. It can also be said that an instance of a class is an object. A class is actually a data type. A class has attributes, which is an abstraction of the state of the object and uses a data structure to describe the attributes of the class. A class has an operation, which is an abstraction of the object's behavior, described by the operation name and the method to implement the operation.

The relationship between objects and classes:

The relationship between classes and objects is like the relationship between molds and castings. The result of the strength of the class is the object, and The abstraction of objects is a class, which describes a group of objects with the same characteristics (properties) and the same behavior.

class person{ }//这个是类
$obj = new person();//类的实例化就是对象

The above is the detailed content of What is a class? What is an object? What is the relationship between classes and objects?. 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