?????м??????if???????????
???????????? ???????[ 2016/7/15 10:26:18 ] ??????????????????? ????
?????????????????????if???????????????????????????????if??????????д?????????????????????????
??????????????????????????????????????????????????????????????а?????????á?
??????if?????????????????????????飬?????????У????????????????????????????????????????????????if????????????????
????if????????
????if????????????????????????if??????????????????????????д???μ?if???
????public void theProblem(boolean someCondition) {
????// SharedState
????if(someCondition) {
????// CodeBlockA
????} else {
????// CodeBlockB
????}
????}
??????????????????????????Щ??????????????δ?????????????????????SharedState?????CodeBlockA??CodeBlockB??????????????δ???????????????????CodeBlock????????????????????????????
????????????CodeBlock????????if???????return???????????????????????????????????????·????
????if????????????????????????????????????if?????domain??????????????????????????£????????????????????????????????????????
?????????????????????????????????????????????????——?????????????С???????????????????????????????????????????ν???????????????????ν?????????????????????????
??????????????????д?????????????????????????仰??
??????????????У??????????????
????if????????????????????????????????????????if????????????????Щ???????????????????????е?if??????????if??????????????????????
???????????????????????????????÷?Χ??
??????????if????????????????????????????????????????if????????????????Σ??????????Ч??
?????????????????Σ????????罻????????????????incoming response?????????????????????????????????????У??????п????gatekeeper?????????????????????????????????ü???????????????????????????
??????1????????????Boolean Params??
?????????? ?з?????????????????boolean??
????public void example() {
????FileUtils.createFile("name.txt"?? "file contents"?? false);
????FileUtils.createFile("name_temp.txt"?? "file contents"?? true);
????}
????public class FileUtils {
????public static void createFile(String name?? String contents?? boolean temporary) {
????if(temporary) {
????// save temp file
????} else {
????// save permanent file
????}
????}
????}
???????? ???????δ?????????????????????????????????????????????????л?????????ж?????????
???????÷?Χ?? ????????????????????????????????????????????????·??????????????????????
????????????? ??????????????????μ?????????if???????
????public void example() {
????FileUtils.createFile("name.txt"?? "file contents");
????FileUtils.createTemporaryFile("name_temp.txt"?? "file contents");
????}
????public class FileUtils {
????public static void createFile(String name?? String contents) {
????// save permanent file
????}
????public static void createTemporaryFile(String name?? String contents) {
????// save temp file
????}
????}
??????2?????????Polymorphism??
?????????? ????????switch???
????public class Bird {
????private enum Species {
????EUROPEAN?? AFRICAN?? NORWEGIAN_BLUE;
????}
????private boolean isNailed;
????private Species type;
????public double getSpeed() {
????switch (type) {
????case EUROPEAN:
????return getBaseSpeed();
????case AFRICAN:
????return getBaseSpeed() - getLoadFactor();
????case NORWEGIAN_BLUE:
????return isNailed ? 0 : getBaseSpeed();
????default:
????return 0;
????}
????}
????private double getLoadFactor() {
????return 3;
????}
????private double getBaseSpeed() {
????return 10;
????}
????}
???????? ??????μ??????????????????????switch?????????????bird?????????????bird???????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11