What exactly is object-oriented PHP? Ten minutes easy-to-understand graphic tutorial

易达
Release: 2023-04-08 16:46:02
Original
3084 people have browsed it

PHP Basic concepts of object-oriented

(1) Basic concepts of object-oriented

1. What is an object

l Object-oriented English is Object Oriented, which when broken down is

- Oriented

- Object (Object)

concept :What is an object

l Everything in the world is an object

n Everything visible

u An old man, a laptop

u A table

u A player

u A female anchor

n Everything invisible can also be an object

u A bacteria in the air

u An abstract concept

l Abstract, as the name suggests, is something that has removed the specific image. For example: People can be said to be a relatively abstract concept, because a specific person has specific characteristics such as gender, age, height, appearance, social relations, etc., but abstract " People is a concept that does not contain these specific characteristics, so it is abstract; and the specific concept of people should be张三,李思wait. Therefore, abstract concepts generally refer to every type of thing, rather than a certain thing.

2. The composition of the object

l The composition of the object consists of two parts

n The components of the object

u is the data model of the object , used to describe the data of the object

u is also called the attribute of the object , or The member variables of the object

n The behavior of the object

u is the behavior model of the object, is used to describe what the object can do

u Also known as the method of the object

      

3. Characteristics of objects

l Every object is unique

n For example, Zhang San is Zhang San, Li Si is Li Si, your table is yours and not someone else’s, and the table in your bedroom is not the table in the living room. These cannot be confused.

l An object is a specific thing, and its function is to complete a specific function

n For example, a table, It is just a table. It is designed to meet your needs when eating. You can put food on it, which makes it convenient to eat.

n Another example is a player. Its function is to pass, dribble, shoot, and dunk. These are what they have to do.

l Objects can be reused ’s

n For example, player James, after he finishes playing basketball, he can continue to play. It does not mean that it is over after playing one game and cannot play again.了

n Another example is the dining table. After you finish eating, you can continue to use this table when you eat next time, so it is OK Being reused

n Another example is a car that drives from Beijing to Guangzhou. It does not mean that it will be scrapped when it reaches Guangzhou, but it can be Back and forth many times

4. What is object-oriented

l Orientation means always keeping the object in mind when programming

n For example, if you face the wall, all you see is the wall,

n For example The teacher lectures for whom it is aimed at, the students, so when the teacher is in class, he must always face the students

n Object-oriented, that is, when programming, My heart has always been object-oriented

l Object-oriented programming refers to converting all data models into object structures for storage during programming,

n In fact, when programming, we convert all data structures into properties and methods and store them in the form of objects. We use this method to It’s called object-oriented programming

5. Why use object-oriented

  • Description of objects The method is more in line with the real world and makes it easier for us to understand the business logic of large projects

n In the early days, we were process-oriented programming, that is, we talked about the organizational structure of the code every day, but with the object description method , we can also say that what I write is one object, and then there are various interactions between them

n In the process of programming, this An object-oriented development method shortens the distance between code and the real world

6. The essence of object-oriented

l We do everything we do It is necessary to observe the essence of things, so the essence of object-oriented is

n Store all the problems to be solved in life through objects. What is Object storage is to store the data structure as the properties and methods of the object

u For example, if we want to make a home software, we can store all the homes in it. Use the properties and methods of the object to represent it, such as its size, color, size, etc.

What are the methods? For example, some furniture can be folded, and this folding is its method

u Another example is a player, what are its attributes, height, age, team, skin color, etc. What about methods, such as dribbling, passing, shooting, Basic skills such as dunking are the player's methods

l The interaction between objects is completed through the invocation of methods. This is a bit abstract, and will be discussed later. We will conduct a detailed analysis through examples

n Examples

u For example, I am from At the door of the classroom, I walked about 10 steps and came to the middle of the podium. Then I looked at Zhang San and asked a question, "Hello, what is your name?" Finally, Zhang San replied: "Hello, I Called Zhang San”

                                                                                                                                                                                                                                  to , and then called the reply method of Zhang San’s objectWhat exactly is object-oriented PHP? Ten minutes easy-to-understand graphic tutorial

7. Basic object-oriented ideas

l

Chapter Step one: Identify the object-Any entity can be called an object

l

Step two: Identify the attributes of the objectn

The data stored in the object are all attributesn

We should pay attention to different businesses The attributes are differentu

For example, in the above scenario, we want to use an object-oriented method to restore it, then the attributes of concern are name, identity , there are 3 methods, walk, look, and ask

u For example, female anchors and players are both human beings, but because their businesses are different, the attributes and methods we focus on will also be different. For example, female anchors, we pay more attention to His stage name, singing, and player. We are more concerned about which team he is on and his skills

l The third step: Identify the object Behavior

n For example, changes in the object’s own data are behaviors

n Object Interaction with the outside

8. Basic principles of object-oriented

l Objects are internally highly cohesive

n Contains only one specific function (the function can be large or small)

u For example, a player is only responsible for playing basketball, and a female anchor is only responsible for singing. Although they can also do other things, because their businesses are different, their functions are different, and other functions are not included

n All object-related content is encapsulated inside the object

l It is low outside the object Coupled

#n The external world can only see some of the properties of the object, but not all

n The external world can only see part of the behavior of the object, not all of it

u This high cohesion and low coupling cannot Coupling is some basic principles of objects. It is also an important principle in our entire programming. In particular, low coupling is more important. Why do you say this? Because once low coupling is achieved, the dependencies between objects will change. It is very small, and the benefits are that it is more maintainable and scalable. For example, if you make a game software, the player object can be used by multiple games, so you can develop new games. When , it can be used directly. In this case, the reusability is also enhanced

u The advantage of high cohesion is that you have everything you should have , try to write it as completely as possible so that there will be no missing arms or legs

u High cohesion and low coupling are not just the basics when we design objects. principle, it is also an important design principle for our programming



The above is the detailed content of What exactly is object-oriented PHP? Ten minutes easy-to-understand graphic tutorial. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!