Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are 3 characteristics, 7 principles and 6 relationships of object-oriented?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "what are 3 characteristics, 7 principles and 6 relationships of object-oriented". In daily operation, I believe many people have doubts about what are 3 characteristics, 7 principles and 6 relationships of object-oriented. The editor consulted all kinds of materials and sorted out simple and useful operation methods. I hope it will be helpful to answer the questions of "what are object-oriented 3 characteristics, 7 principles and 6 relations"! Next, please follow the editor to study!

According to the syntax of PHP, different programming languages have different ways, but they are generally the same.

The idea of object-oriented is to understand and use.

The interfaces mentioned in this article are all programming language syntax interfaces (interface), not front-end calls (api).

Why are there so many concepts? I know why it is.

Software, is to solve the problem of human development, convenient tools for human beings, if a computer, or a software can only count, then how to meet the exchange rate conversion? Can it be said that the computer itself cannot accomplish something if it does not have too many inherent functions? Today's software can help people shop, date and entertain. In terms of such a complex function, if the software idea does not develop a more advanced idea, it cannot serve human beings, so in order to be more maintainable and have stronger functions, some more advanced concepts must be put forward in the computer software programming itself to achieve more complex functions than addition, subtraction, multiplication and division, and diversified rules have become a set of practical and efficient specifications. Then there are all kinds of computer nouns seen below.

Object-oriented

"facing" here can be understood as what train of thought to program.

Object

Object is a kind of programming idea according to things as the center, everything is object, events are caused by entities, objects are real, objects can also be understood as data structures and methods to deal with them, constitute objects. It achieves the three goals of software engineering, reusability, flexibility and expansibility. Reusability: methods in a class can be used multiple times. Flexibility: can be shown as polymorphism, repeatable transfer and other characteristics, high degree of freedom, all roads lead to Rome. Extensibility: both polymorphism and inheritance have this feature, which makes it easy to diversify, extract, and reduce coupling.

Class

It can be understood as the abstract concept of object, which separates the same characteristics and classifies them. The object of the same behavior is classified into a class, a person is an object, but more than one person can be summed up as a human, human does not refer to a certain one, but a virtual entity concept. Why is there such a class? Because people have hands, can use fire, have civilization, strong learning ability and other factors, if you want to talk about someone from human beings, it is to give an example, that is, instantiation.

Member attribute

Attributes can understand data, which is the carrier of information and presentation. According to people, for example, people have noses and eyes, and this is the attribute of people. It can be described as having.

Member method

Method can be understood as a function. The method is to control the butler of the data. According to people, for example, people can talk and eat, this is the way of people. Can be used to describe.

Interface

It can be understood that a class needs to specify what it needs to do, but it does not need to do it, which serves as a specification example, which is a standard and requires other classes to implement it. For example, the definition of the usb interface size, size, data line connection method, can be compared to an interface specification, the world's usb interface is common, whether it is U disk, charger cable, mouse, keyboard. These examples can be used to make things according to this constraint specification. The use of the interface needs to be described by the word implementation.

Three properties of the class

Encapsulation: by encapsulating the internal methods or data of hidden classes, only accessible resources are allowed to ensure security. In terms of personification, the name is public, the bank password information is personal, and the PHP can be modified with public protected private.

Inheritance: inheritance generalizes the class, and the son inherits the father, can get non-private properties of the parent or parent up, or methods, using the extends keyword.

Polymorphism: dynamic dispatch based on object type can be realized. Different people do the same thing and get different results. The matter of blind date: girls will say get out when they encounter hooligans and what will they say when they meet handsome guys.

Object-oriented programming under the seven principles, purpose: interface-oriented programming, aiming at the goal. Simplify the code and reduce the coupling. Flexible separation to reduce impact. Extract the same code to facilitate reuse and maintenance.

Single principle: a class does one thing, and the responsibility is completely encapsulated in a class. It will not cause confusion, improve reusability, and low-coupling design can reduce the maintenance in the later stage of software development.

Opening and closing principle: closed for modification and open for expansion. The code needs to be changed because of the change of requirements, the upgrade of the running environment and other reasons. If there is no bug, then it is not recommended to change the original code and can be expanded on the original basis. It not only increases the expansibility, but also ensures that there is no problem with the original logic. The so-called "ancestral code, do not move", that is what it is.

Richter's substitution principle: generally speaking, wherever the father can be used, the son can also use it. The base class object that can be used in the software, then it is necessary to make sure that the subclass object can be used anywhere without being affected. That is, subclasses can replace wherever the parent class appears in the program, and ensure that the logic remains the same and correct, which implies that rewriting the parent class is not recommended. It is precisely because of this standard that we can prevent the failure of the children if the parent is modified. This principle implements the form of the open-close principle, and the subclass is equivalent to an extension. In essence, this principle is to tell us the problems that inheritance needs to pay attention to and the principles to be followed. However, inheritance increases the coupling relationship between parent and child classes. in order to solve the dependency, it can be solved through aggregation, combination, dependency and so on.

Dependency reversal principle: interface-oriented programming. Putting shared reusable methods into abstract classes, abstract thought programming, or interfaces, according to abstract coupling is the key to the principle, with the aim of reducing coupling. High-level modules (for example: high-level modules are the code at the bottom of the framework, according to PHP, many of the code at the bottom of the framework are abstract classes or interfaces) do not rely on the underlying modules, both rely on abstraction. Abstraction should not rely on details, details should rely on abstraction, that is, to achieve the separation of details and non-details, compared to the variability of details, abstract things are much more stable. An abstract-based architecture is much more stable than a detail-based architecture. For example, the general implementation of the function can be implemented using abstract classes, but the details can be implemented with concrete classes. The so-called abstraction here is used to customize the specification and the overall architecture. Take a chestnut:

/ / this code is suitable for sending email, but is it troublesome to add the function of sending Wechat? Do not mention that "Email $email" is removed here. If a large number of business logic in the project has been written in this way, removing "Email $email" may cause problems.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report