The essence of object-oriented (JAVA, C ++)

The difference between the object-oriented and process-oriented:

A child learned pascal, c inter-professional self-study language, are process-oriented programming
and now to learn C ++, python, java is object-oriented programming.
Goes online is a different design approach of
the programming process : You can see every step to solve the problem, each step may have inextricably linked.
Object programming : you can only see what modules to solve any problem, are independent modules, and how to solve the specific process, it is of a black box.
Although the issues have been resolved, but in different ways.

Say this is not easy to understand: I think the objects and the process of difference is very simple :
1. object-oriented programming is a derivative of complex engineering projects
2. extreme point, object-oriented programming is the process of optimizing the programming
before object-oriented programming has not come out before, that when the project amount is still small, their program ape in machine language can solve the problem, and then later, in order to facilitate understanding escalated into assembly language, after this development has c language normal people can understand, then the human brain for tens of thousands of lines of code thousands of lines of treatment can endure, along with the popularity of science and technology, when the project complexity increases, the number of lines of code into a multi-billion row, people gradually powerless, able to think of ways how readable code , scalability is improved in a short time it can be clearly understood that the logical framework of a project, then the object-oriented born.

I studied engineering, in fact, this trend, the first sequential second industrial revolution can be seen, whenever a complicated thing once it contrary to our original intention for human use, because we were born to be lazy ,
former craftsmen hand-able make a commodity, and later to replace the manual machine.
The purpose is for people to easily car to drive, we do not need to understand the structure of the engine.
The purpose of the integrated circuit is considered to bring computer power, performance materials and circuit theory nor we need to know.
Today, the aim is to liberate human artificial intelligence to achieve very environment of mankind lazy , we do not understand the mathematics behind the mystery.

: Programming is simple good program
1. straightaway ( readability )
2. The future can continue to use ( robustness )
3. easy CRUD functionality module ( scalability )
can be applied across multiple projects 4. ( reusability )
5. issue any course changes by others mistakes not ( serviceability )
6. fastest speed and resolve to complete the task ( low complexity of )
short on one purpose: to experience problems after I save more this bar code is more

This is an object-oriented development of the cause.

Objects and Classes

There is a saying: Everything Is an Object, all things are like, sometimes I think, the computer is not also refer to the principle of Margery. This clearly is an individual and general dialectical relationship thing! !
I do not believe, then replace individual objects into general classes, I come to you recite it again Margery dialectical principle:
The object must be linked with the class and can only exist by the presence of an object class, any class of objects are (part of) any class is an object of (nature). just like any objects generally include all things. any object can not be fully included in the class, classes and objects into each other, touch each other .

Of course, a joke, to a specific project, classes and objects are identified, of course, it can not be transformed into each other, or else went wrong, but above Margery well elaborated both a direct relationship,
 that refers to class, and the object of it, in fact, with a finger.
 For chestnut:
 When I define a class mouse and the mouse as a general reference, then the mouse close association label is like a mouse with a finger.
 When I define a class computer accessories, accessories refers to this time, the mouse is the accessories category with a finger.
 Written in the program, we create an object, you want to instantiate

C++
class Mouse
{
    public:
    	int click;
    //公共的行为或属性
}
int main(){
	// 两种不同的创建对象方式
	Mouse mouseWithLenovo = Mouse(); //栈中分配内存
	Mouse *mouseWithLenovo = new Mouse();// 堆中分配内存
}

JAVA
// 创建类
public class Mouse{
	String click; 
}
public static void main(String[] args){
	// 实例化对象
	Mouse mouseWithLenovo = new Mouse();
}

inherit

Inheritance is a subclass inherits characteristics and behavior and the parent class, so that the subclass object (instance) with the parent class instance fields and methods may also be added in this new basis for methods and fields to meet demand.
That subclass can call methods and properties of the parent class, even the parent class can rewrite according to their own unique characteristics.

Abstract class.

1. An abstract class can not be instantiated , abstract class must be inherited . (Design considerations clearly)
2. abstract class is a special case of a rule class, this class does not depict a specific information object.
3. The abstract class can write specific method , you can also write an abstract method .
4. An abstract class is used to capture characteristics common subclass .

interface

1. Interface can be used to instantiate the object .
2. Interface no constructor .
3. All interface methods must be abstract methods . (Formerly 1.8)
 after 1.8 non-abstract method can also be . (Method does not implement)
4. Interface not contain member variables, and in addition to static final variable.
The interfaces are not inherited by the class, but the class is to be achieved .
6. The interface supports multiple inheritance .

The difference between abstract classes and interfaces:

Here Insert Picture Description
Here Insert Picture Description

scenes to be used

1. abstract class required methods implemented
using multiple-inheritance interfaces 2.
3. The basic function of the increasing time to use an abstract class
4. When using the interface function increasing need to modify each implementation class that implements the interface

Construction method:

1. The method of construction without reference

Constructor is used to initialize a class member variables of the object is formed of a member variable value-free.

2. Method configured with parameters

Constructor forms a more customized objects (i.e., objects with parameter values)

Method overloading

premise

1 have the same function or method name.
2. The parameter list are not the same (including the number and type of parameters).
3. Return values are different is not overloaded.

Constructors have the same name as the reference points with no parameters is a reflection of a method for actually overloaded.
Ordinary methods have the same name without reference parameter is a reflection of method overloading.

Package

Packaging is an abstract concept, intended to hide implementation details to form a black box, the user to
implement the package is achieved through inheritance and interfaces
1. What needs to inform the abstract methods to implement the interface , the abstract class or parent to implement the abstract class affiliation
2. a successor be embodied by all subclasses methods, the details of the picture.
3. Foreign only expose interfaces, so users can not understand its internal principle.

Published 19 original articles · won praise 4 · Views 489

Guess you like

Origin blog.csdn.net/qq_35050438/article/details/104061311