From today on, I began to summarize Master Gao hentang's "road to Android architect" and try to write three blog posts a week. Reading an article is a little faster than watching a video. However, watching a video is also quite detailed. If you are interested, let's continue with my serialization. I recorded my understanding and shared it with more people who needed it. Let's not talk much about it. The first article is "Basic OOP knowledge ".
For the current programming language, object-oriented is no longer a word that is hard to understand. But how can we fully express our ideas? This is what we need to care about. This article hopes that teacher Gao hentang will bring us a different world.
1. Definitions of Oriented
In most cases, we regard it as orientation, and I have understood it as a way of facing this kind of meaning. However, I have heard a new meaning "faith ". What is Faith? In the hearts of Christians, Jesus is their faith, their God, and nothing else. In the designer's mind, we should treat the object as the "God" in our hearts. If we have problems and troubles, we can only seek help from them. We need to believe that the world of software is composed of objects, but nothing else. Oriented perfectly interprets this connotation, in addition to orientation and "belief ". In the computer world, how can we express this belief? You only need to define the class.
Here are a few words to really understand the meaning of oriented (Oriented Based driven centered ):
Based:
Similar to building a house, the foundation is the foundation of the house. In the description of the based term, it is more important to emphasize a successive relationship, namely, building the foundation before and after the house is built.
Another example is requiredment-based: based on requirements, there is a sequence. First, conduct demand analysis, and then carry out post-release house arrest development activities based on the results of the demand analysis, which becomes requiredment-based software.
Driven:
We understand the literal translation of driven as a driver, which is inconvenient for us to understand its true meaning. In fact, this word is more "guiding" and Guiding Direction (just like the meaning of the existence of the Polaris, guiding people forward ). Just like a driver driving a car, the driver does not actually drive the car forward, but guides the car forward. The engine is the real driving force of the drive car. Use Case Driven case-driven development is to tell us that our software development should follow the user's thinking and understanding, and carry out our software development without changing the general direction.
Centered:
Taking ...... as the center, the construction of the house first draws the design drawing, the construction of the House's girders (outlines), and later development is built around the outline. Christmas candy boxes are all hooked up on Christmas trees.
Architecture-centered all software development activities are centered around the architecture
What does Service-Oriented Architecture (SOA) mean?
I believe that the software world is composed of all services.
Ii. Starting from the object
There are all kinds of things in nature. With the increase of experience, people are increasingly familiar with things in nature. For individuals, what they know. All are objects. For example, Li Bai's clearest object is his poems. Each poem is an object, while the European poems are not Li Bai's objects. From this perspective, objects are the simplest things we can recognize. Once you know something, you can express its characteristics and compare it with other objects. Objects in nature have the following characteristics:
Features or attributes of objects (static features)
Behavior of objects (Dynamic Features)
We believe that software is composed of objects, so the objects of software should have the characteristics of natural objects.
A software object is composed of data (the phase of a natural object) and functions (the behavior of a natural object.
Iii. Usage of category: Brief description of software objects
Class is a group, and the object is a part of the class. People often use is a to express the relationship between objects and classes. Class is a group of objects with common important features. The definition of a class is an important feature of this group of objects. Features include the features and behaviors of objects.
Objects in software use data to express features and functions to express behavior. Because, the definition of a class is to describe the objects in the software, which should contain the data and those functions.
Iv. Purpose of the <base class \ subclass> structure 1. represents inheritance
Sub-classes can inherit the attributes and behaviors of the parent class, or define their own attributes and behaviors. Convenient Reuse
2. indicates a combination
The thread calls the start method to open a new thread, calls the run method in runnable, and uses the subclass task method.
The subclass directly inherits the extended thread, and the thread generates a sub-thread to execute the run method.
5. interfaces of the <base class \ subclass> Structure
The so-called "Hook" is an interface used to connect two things. If the two parts do not appear in the same time period, the void part of the two parts will be reserved, and the other side will be able to fill the space with entities in the future. The two parts will be sealed together if they are mutually dependent. Well-designed interfaces allow you to easily implement metabolism, change freely, or even cross-platform software.
? Separate code that changes from the code that doesn't is the basic principle and technique for designing the hook function and application framework.
? After the variant and invariant parts are separated, you can write the unchanged parts in the super-class, and the changed parts are written in the subclass).
The purpose of splitting is to better stay with each other and separate the changes.
C ++ combines them with an inherited machine (inherit)
Java extended extends
JAVA Implementation of the snap-on function:
In Java, you can use abstract functions or overridable functions to implement the snap-on function.
Vi. IOC mechanism and default Function
IOC: inversion of control)
? The IOC mechanism is derived from the class inheritance system of OO languages (such as C ++). For example, in C ++ languages, basic functions can actively call subclass functions, this is a typical IOC mechanism.
Between the base class and subclass, the main control permission is in the hands of the base class, And the subclass is called through the hook function.
? Generally, the base class is written first, while the sub-class is written later. This kind of predecessors have the dominant power, and then "control" the latter is called "control inversion 」.
Important features of the base class: Provides default (preset) behavior
? The base class can define many default functions in advance. These default functions allow subclasses to inherit (or call.
VII. Active vs passive APIs
Interface between systems: Ui, interface between software system module and module: API
API type
For APIs, there are three closely related three verbs: The definition (define) Implementation (implememt) Call (invoke or call). According to these three perspectives, APIS can be divided into two types: active and passive.
Passive API: I define my implementation, called by the other party (geographic snake)
Active APIs: I define, implement by others, and call (strong Dragon)
Meaning of API:
In other words, an API is control. The interface is the contact between the two sides, and also the connection between the power of both sides and the chassis. Who has the right to establish interfaces and who has the control points can gain a greater initiative, which belongs to the strong dragon party, while the other party is passive and becomes a weak party and plays the role of the ground snake.
Basic OOP knowledge