Stop obsessing about what's on the ground, what's the technology, learn to think, change the mindset
I. Status of Enumeration
In your usual coding you will find that many design patterns are not the same type of figure, which makes the enumeration of the indispensable status (type)
Second, constant
We often use constants to define some error codes, etc.
If it's a constant, your code might be like this.
1 Public Final Static classsysmsg{2 Public Static FinalStatus_success_code= "0";3 Public Static FinalStatus_failure_code= "-1";4 Public StaticFIANL sys_success_code= "1000";5 Public Static FinalSys_sign_code= "1001";6 Public StaticFIANL sys_sing_msg= "Illegal Request"; 7}
This is the case with enumerations.
1 Public enumenumt{2SUCCESS (1, "Operation succeeded"), FAILURE (1, "Operation failed"), FAILURE (4, "Signature failed");3 PrivateString name;4 Private intindex; 5 PrivateENUMT (String name,intindex) {6 This. name=name;7 This. index=index;8 }9 PublicString GetName (intindex) {Ten for(Enumt c:enumt.values ()) { One if(c.getindex==index) { A returnc.name; - } - } the return Nuljul; - } - PublicString GetName () { - returnname; + } - +}
Iii. creating a String constant enumeration
Public enum enumtask{ INITIAL ("Initialize"), processing ("in process"), processed ("Processing done"), FAILURE ("Processing failed"); Private String status; Enumtask (String status) { this. status=status; } Public String getStatus () { return status; } }
Four, reverse lookup method
I believe you see the above example has some insight
Reverse lookup ideas Define a map static code block that uses traverse values () to provide an external calling method using the value as a key setting map
It would be useful to use enumerations skillfully in the design.
Java Const Enumeration Method