Java (II) -- OOP Design Philosophy

Source: Internet
Author: User
Tags form tools

Java (II) -- OOP Design Philosophy
(1) The origin of oop in java


Machine language: directly composed of computer commands. commands, data, and addresses are "0" and "1": can be directly executed by the computer.

Assembly Language-it represents commands, data, and registers with symbols that are easy to understand and remember. The abstraction level is low, and programmers need to consider a large number of machine details.

Advanced Language-a natural language connected to military personnel, proposes structured data and statements for data and process abstraction.

Object-oriented-abstract a realistic thing.


(2) design ideas of OOP


We can see that the design idea of OOP is: what classes are there? What are the methods of these classes? What are the attributes of these classes? What is the relationship between classes? <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + PGJyPgo8L3A + CjxoMj4xoaLA4Dxicj4KPC9oMj4KPHA + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20140909/20140909084159153.png" alt = "\">



Classes provided to us in the underlying file of Java itself are the core classes that we often use. Network classes can be called through TCP and UDP protocols; IO classes, data streams are used to read and write files. Tool classes include form tools, Java forms and components, and tools and containers. To use these classes, you need to reference them because only eight basic data types in Java do not need to be referenced. When using other objects, you must first reference them.


2. Method (dynamic attribute)



Java contains all the Java classes and methods we need. A good programmer must learn to use this api file. Of course, in the video, Jack Ma explained the method by using the constructor method. from special to general, the constructor method has the same name as the class. A class can have many constructor methods. The difference between the methods is: the number of parameters. The parameter types are different. The constructor is called during instantiation.


Memory analysis:


We mainly analyze the third step: During the execution,

(1) heap is the stack, and new items are put here, the returned values are temporarily put here, and the local variable name is put here;

(2) Stack is a heap, local variable values are put here, and new parameters are put here.

When the function execution ends, all data is released.

(3) Data Segment stores static variables, it is the use of stati ╧ y "http://www.bkjia.com/kf/yidong/wp/" target = "_ blank" class = "keylink"> WPJ + cP3tcSx5MG/templates/ydLU1rG908Dgw/smIzQzO7Hkwb/D + Memory = ""alt =" \ ">



3. attributes (static attributes)



Pay attention to the attributes declared in static mode.


4. Relationships between classes



We have discussed these relationships in UML. In the design pattern, pay attention to how these relationships are implemented in the code.


5. Principles



There are two differences in inheritance:

(1) differences between an interface and an abstract class: if an interface is inherited, all methods in the interface must be implemented. If an interface inherits an abstract class, no methods are required. A class can inherit multiple interfaces, only one abstract class can be inherited.


(2) Reload and rewrite: very simple:

Overload means that multiple methods can be created in the class. They have different parameter tables (parameter types and numbers), but the same name represents a type of polymorphism.

Rewrite: it is a polymorphism between the parent class and the Child class. The Child class inherits the methods in the parent class, and does not need to be rewritten. Simply put, it is overwrite, the subclass has the same method name, return type, and parameter table as the parent class.


Just pay attention to it.



(3) Summary


I personally think the OOP mentioned by Jack Ma has changed many self-righteous ideas. What the teacher said: What you have done is new objects and objects. the method is used after it is called out. It is a completely process-oriented idea. A master programmer considers the classes, methods, and attributes of these classes, what is the relationship between classes? This is the idea of object-oriented.












Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.