Tag: Lib generates a computed taxonomy that inherits C # phones ...
Object-oriented concepts
First, the programming paradigm
in our programming language, it can be broadly divided into two broad categories: imperative programming and declarative programming
- Command-type programming
The so-called command-based programming, is to command-oriented, to the Computer A command, the computer to follow our instructions to the intact execution.
How to command the machine to do things (how)
common command-style programming languages are: C Language, C+ +,C #,Java,PHP,Ruby
from the imperative programming language can be divided into two major categories: process-oriented and Object-oriented
(1) Process-oriented
is to analyze the steps needed to solve the problem, and then take these steps step-by-step
(2) Object-oriented
The so-called object-oriented is to consider the model inside the program as a single object. Objects and objects can have a relationship with each other. Using objects to solve problems
It is important to note that even object-oriented programming has process-oriented steps.
- Declarative programming
the so-called declarative programming means telling the computer what you want (what) , let the machine to solve how to achieve.
declarative programming can also be divided into two main categories: DSL and functional programming
(1) DSL
DSL translates into Chinese as domain-specific language (domain specific Language). As the name implies, refers to a particular field of language.
of Common DSL language has HTML,CSS,SQL
(2) Functional programming
Consider some of the models inside the program as functions in math to calculate.
Second, object-oriented
- What is object-oriented
the first thing to figure out is what the object (Object) . In layman's terms, it is something. Our world is made up of all kinds of things. There is a connection between things and things.
in real life, when we describe a thing, or an object, we often describe it in 2 ways .
For example, I want to describe a cell phone
First, the first one is the appearance . ( Properties ) : White 5.5 inch Rectangle
The next step is to describe the function: watching a movie Call Play Games
- Object-oriented and process-oriented differences
Process-oriented features: From top to bottom, execute sequentially, we need to consider each step.
Object-oriented features: Object-oriented more in line with our human thought. We just need to find the objects we need.
ATM machine Take money
Process-oriented: we need to consider each step, such as the amount of money to be taken, the balance is how much, the user's input is legal
Object oriented: Just consider this the ATM object can be
- Object-oriented features
Generally speaking, there are 3 object-oriented features : encapsulation, inheritance, and polymorphism
some old textbooks will tell you that there are 4 object-oriented features : In addition to the above 3 , there is an extra abstract
Encapsulation: It is to hide the details and not expose them to the outside. In real life, for example, a television is a typical package that cannot see the details of internal electronics
Inheritance: As in real life, a son can inherit something from his father. In the program, the face class can inherit the parent class.
Polymorphism : If from a language point of view, it is different objects the same method does not work the same way. For example, in real life, the word "action" is not the same for people of different professions.
- Class
as in real life, things are a lot, according to People's thinking naturally will think of classification. For example, give you 1 million books. We will first think of classification, such as classified as fiction, science and technology, comic, political, economic ... The books under each category have common features.
Class and object relationships: A class is a generalization of an object, an abstraction, an object is a concrete implementation of a class, and is a concrete thing.
- Creating objects
(1) How the common programming language produces objects
Objects are generated from the class. So if we're going to get the object, we first need to create the class
For example: How to create classes and objects inside PHP
Now that the object is instantiated from inside the class, you first need to have a class
And then we can produce concrete objects from the class.
(2) How to create objects in JS
in the before ES6,JS had no concept of class. So before ES6 , the class was modeled by a function.
Functions that emulate classes are often called constructors. To differentiate between constructors and ordinary functions, there is an unwritten rule that the function name of the constructor is capitalized in the first letter
Diagram of objects and constructors, and prototype objects (important)
The arrays, functions, numbers, strings, and so on that we are talking about have the corresponding constructors. If it is instantiated through a constructor, it is an object
there is a property called constructor in the object that can be viewed to the constructor of this object
within each constructor, there is a hidden property called prototype, which points toan object that is the prototype object of an object instantiated by a constructor
constructor function.
JS Object-Oriented Foundation