Home > Backend Development > PHP Tutorial > php object-oriented tutorial 1

php object-oriented tutorial 1

黄舟
Release: 2023-03-04 12:18:02
Original
1444 people have browsed it
  1. The concept of object-oriented
    Object-oriented programming (Object Oriented Programming, OOP, object-oriented programming) is a computer programming
    architecture. One of the basic principles of OOP is that computer programs are Composed of a single unit or object that can function as a subroutine, OOP
    achieves the three goals of software engineering: reusability, flexibility, and extensibility. In order to implement the overall operation, each object can receive
    information, process data and send information to other objects. Object-oriented has always been a hot topic in the field of software development. First of all,
    Object-oriented is in line with the general rules of how humans look at things. Secondly, the use of object-oriented methods can make each part of the system perform its duties and do its best. It opens a door for programmers to make their programming code simpler, easier to maintain, and more reusable. Some people say that PHP is not a true object-oriented language, and this is true. PHP is a hybrid language. You can use OOP or traditional procedural programming. However, for large projects, you may need to use pure OOP
    to declare classes in PHP, and only use objects and classes in your project. I won’t go into detail about this concept, because the main reason why many friends stay away from object-oriented programming is that they can’t understand the object-oriented concept when they come into contact with it, so they don’t want to learn it. Let the readers of
    understand the concept after reading the entire content.
    2. What is a class, what is an object, and the relationship between classes and objects
    Concept of class: A class is a collection of objects with the same attributes and services. It provides a unified abstract description for all objects belonging to this class, which includes two main parts: properties and services. In object-oriented programming languages, a class is an independent program unit. It should have a class name and include two main parts: attribute description and service description.
    The concept of object: An object is an entity used to describe objective things in the system. It is a basic unit that constitutes the system. An
    object consists of a set of properties and a set of services that operate on this set of properties. From a more abstract perspective, an object is an abstraction of something in the problem domain or implementation domain. It reflects the information that needs to be saved and the role that the thing plays in the system; it is a set of properties. properties and a set of services that have the authority to operate on these properties. The objective world is composed of objects and the connections between objects.
    The relationship between classes and objects is like the relationship between molds and castings. The instantiation result of a class is an object, and the abstraction of a type of object is a
    class. A class describes a group of objects that have the same characteristics (properties) and the same behavior (methods).
    The above is probably their definition. Maybe you are a friend who is new to object-oriented. Don't be confused by the concepts. Let me give you an example. If you go to Zhongguancun and want to buy a few assembled units. PC, what is your first step when you get there? Is the installation engineer sitting with you and completing an installation configuration list with you based on the information you provided? This configuration list can be thought of
    Xiangcheng is a category, it is just a piece of paper, but it records the information of the PC you want to buy. If you buy 10 machines with this configuration
    , then these 10 machines will all be configured according to this configuration. It is composed of single machines, so these 10 machines are of the same type, or they can be said to be of the same type. So what is an object? The instantiation result of a class is an object. The
    machines configured (instantiated) using this configuration sheet are objects, entities that we can operate, 10 machines, 10 objects. Each machine is independent, which only means that
    they are of the same type. Any action taken on one of the machines will not affect the other 9 machines, but I modified the class, that is, in the
    configuration If one or less accessories are added to the list, all 9 installed machines will be changed. This is the relationship between classes and objects (the
    instantiation result of a class is an object).
    3.What is object-oriented programming?
    Not to mention his concept, if you want to build a computer classroom, you must first have a room with N computers,
    N tables, N chairs, whiteboards, projectors, etc. , what are these? As we just said, these are objects, entities that can be seen. It can be said that the units of this computer classroom are these entity objects. Together they make up this
    computer. Classroom, so we are doing programs, what does this have to do with object-oriented? Developing a system program is similar to building a computer classroom. You abstract each independent functional module into a class and form an object. The system is composed of multiple objects. These objects can receive and process information. Interact with data and send information to other objects, etc. It constitutes an object-oriented program.






    The above is the content of PHP object-oriented tutorial 1. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

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