Java (ii)--oop design ideas

Source: Internet
Author: User
Tags form tools

(i) The origin of OOP ideas in Java


Machine language-Direct computer instructions, instructions, data, addresses are "0" and "1" Composition: can be directly executed by the computer.

assembly language-with easy-to-understand and memorable symbols for instructions, data, and registers, the abstraction level is low and programmers need to consider a lot of machine details.

High-level language-the natural language of the military, the structure of data and statements, for data and process-oriented abstraction.

Object-oriented-abstraction is the real thing.


(ii) OOP design ideas


From what we can see: OOP's design idea is: What classes are there? What are the methods of these classes? What are the properties of these classes? What is the relationship between classes and classes?


1. Class



Java itself in the underlying file to provide us with the class, there is a core class, is what we often use, the network of classes can be implemented through TCP and UDP protocol calls, there is IO class, is the data stream implementation of the file read and write, tool class, there are form tools, you can generate Java forms and components, etc., there are tools, There are containers and so on. To use these classes, refer to them, because in Java there are 8 basic data types that need to be referenced before they are used only for other objects.


2. Methods (Dynamic Properties)



Java has all the Java classes and methods we need, a good programmer to learn to use this API file. Of course, the horse soldiers in the video teacher explained the method with the construction method, from the special to the general, the construction method and the class name, a class can have a lot of construction methods, the difference between the method is: the number of parameters, the types of parameters are different. The constructor is called when it is instantiated.


Memory Analysis:


Our main analysis is the third step: in the process of implementation,

(1), Heap for the stack, new out of things, are placed here, the return value is temporarily placed here, the local variable name is placed here, etc.;

(2), stack for the heap, the value of the local variable is placed here, the new out of the formal parameters here and so on.

When the function execution is finished, all data is freed.

(3), Data Segment is to store static variables, is the variable declared with static, do not need to instantiate, you can directly class name + variable name can be accessed.

(4), code segment store codes.

(5), this memory analysis




3. Properties (static property)



Notice the properties of the static declaration here.


4. Relationships between Classes



These relationships, which we have discussed in UML, are primarily to be noted in design patterns in how these relationships are implemented in code.


5. Principles



There are two differences in inheritance:

(1), interface and abstract class difference: Inherit the interface, to implement all the methods in the interface, two inherit the abstract class, do not implement all methods; A class can implement multiple interfaces, but only one abstract class is inherited.


(2), overloading and rewriting: very simple:

Overloading is the ability to create multiple methods in a class that have different parameter tables (parameter types and numbers), but the same name is the representation of a class's polymorphism.

Rewrite: Is the polymorphism between the parent class and the subclass, the subclass inherits the method in the parent class, but does not need to write from the new, is simply the overwrite, the subclass and the parent class have the same method name, the return type, the parameter table.


Just take a look.



(iii) Summary


Personally, the teacher said that OOP changed a lot of ideas that were thought of before, the words that the teacher says: The new object you have made, Object. The method, which is used after the tune-up, is completely process-oriented, while the master programmer is thinking about what classes, what methods are in these classes, what properties are there, and what is the relationship between classes and classes, which is the object-oriented idea.












Java (ii)--oop design ideas

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.