Java11-java Grammar Foundation (10) class design comprehensive case
Integrated Design method of Class I.
1. Class Design Steps
(1) Analyzing data members
(2) Analysis of member methods and construction methods
(3) Draw a class diagram
(4) Coding test
2. Specific issues
1) Analyze data members
(1) Access control modifiers
(2) Definition of data member name
(3) Definition of data member type
(4) Initial value
Serial number |
Access Control modifiers |
data member types |
data member name |
Description |
1 |
Private |
String |
StudentID |
School Number |
2 |
Private |
String |
Name |
Name |
3 |
Private |
Double |
Score |
Results |
...... |
...... |
...... |
...... |
...... |
2) Analysis of construction methods and member methods
(1) The constructor method is used to initialize the object:
Use three construction methods: Empty construction method, basic information, all information. Specific as
(2) member methods represent the dynamic characteristics of a member, that is, the behavior of the object, including setters, getters, and functional methods.
3) Draw a class diagram
Using UML tools to analyze data members and member methods to draw class structure diagrams
-Studentid:string ("-" means private)
+ getstudentid:string ("+" means public publicly)
o setstudentclass:void ("o" denotes protected)
Software: PowerDesigner
PowerDesigner How to use
1. File---New model---model types---OOM---Class Diagram, named below, language is Java
2. Right---Toolbox---class Diagram---class (second icon)
Second, the Static keyword
When a class produces an instantiated object, it will separate the stack memory and heap memory, the stack memory holds the object name, and the heap memory holds the object's data members.
1. Application
1) Modifies a data member, becomes a class member, also known as a static member, and the data member is shared by all objects of that class.
Definition: Static data type data member name;
Access: Class name. static member;
2) Modify member method, member method can be called directly by class
3) modifies the code block, which is executed when the object is instantiated.
Emphasize:
(1) by object name. Static members can access the object, but once you change the static property of an object, the static property of the other object changes.
(2) A static method can only invoke static data members, and cannot invoke non-static data members.
(3) Non-static methods can access call static members and methods, or they can access non-static data members and methods.
2) Static code block/static initialization block: Only one time when class load is initialized
static{
Initialize content
}
2. Principle: The process of initializing the object by the JVM
3. Main method
Iv. Array of objects
Declaration: Class name [] Object name = new class name [array length];
Assignment: Class name [] Object name = {};
Java11-java Basic Grammar (10) class design synthesis case