search
HomeBackend DevelopmentPHP TutorialWhat exactly is object-oriented PHP? Ten minutes easy-to-understand graphic tutorial

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!

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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools