OO绗笁鍗曞厓鎬荤粨

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OO绗笁鍗曞厓鎬荤粨相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/person' title='person'>person   绫诲瀷   杩涘叆   man   expect   inf   lse   ora   sign   

1.姊崇悊JML璇█鐨勭悊璁哄熀纭€銆佸簲鐢ㄥ伐鍏烽摼鎯呭喌

JML绠€浠嬶細

JML(Java Modeling Language)鏄敤浜庡Java绋嬪簭杩涜瑙勬牸鍖栬璁$殑涓€绉嶈〃绀鸿瑷€銆侸ML鏄竴绉嶈涓烘帴鍙h鏍艰瑷€(Behavior Interface Specification Language, BISL)锛屽熀浜嶭arch鏂规硶鏋勫缓銆侭ISL鎻愪緵浜嗗鏂规硶鍜岀被鍨嬬殑瑙勬牸瀹氫箟鎵嬫銆傛墍璋撴帴鍙e嵆涓€涓柟娉曟垨绫诲瀷澶栭儴鍙鐨勫唴瀹广€?/span>

The Java Modeling Language (JML) is a behavioral interface specification language that can be used to specify the behavior of Java modules. It combines the design by contract approach of Eiffel and the model-based specification approach of the Larch family of interface specification languages, with some elements of the refinement calculus.

浣跨敤 JML 鏉ヨ鏄庢€у湴鎻忚堪鎵€甯屾湜鐨勭被鍜屾柟娉曠殑琛屼负锛屽彲浠ユ樉钁楀湴鏀瑰杽鏁翠釜寮€鍙戣繃绋嬨€?/span>

JML琛ㄨ揪寮忥細

琛ㄨ揪寮?/span>鍚箟
esult 鏂规硶杩斿洖鍊?/span>
old() 琛ㄧず杩涘叆鏂规硶鏃跺埢鏌愪釜鏁版嵁鐨勫€?/span>
(forall ; ; ) 鍏ㄧО閲忚瘝
(exists ; ; ) 瀛樺湪閲忚瘝
a==>b a鎺ㄥ嚭b
sum 缁欏畾鑼冨洿鍐呰〃杈惧紡鐨勫拰
um_of 鎸囧畾鍙橀噺涓弧瓒崇浉搴旀潯浠剁殑鍙栧€间釜鏁?/span>

JML宸ュ叿閾撅細

  • OpenJML锛岄潤鎬佹鏌ュ櫒锛屽JML璇硶杩涜妫€鏌?/span>

  • JMLUnit锛屽彲浠ュ熀浜嶫ML娉ㄩ噴鐨刯ava鏂囦欢鐢熸垚JUnit娴嬭瘯

  • SMTSolver锛屽湪閫昏緫灞傞潰銆佸浠g爜瀹炵幇褰㈠紡鍖栭獙璇併€?/span>

銆€銆€銆€銆€銆€

2.閮ㄧ讲JMLUnitNG/JMLUnit锛岄拡瀵笹roup鎺ュ彛鐨勫疄鐜?strong>鑷姩鐢熸垚娴嬭瘯鐢ㄤ緥锛屽苟缁撳悎瑙勬牸瀵圭敓鎴愮殑娴嬭瘯鐢ㄤ緥鍜屾暟鎹繘琛岀畝瑕佸垎鏋?/span>

灏濊瘯浜嗚窇鍚勭鏍峰瓙鐨凪yGroup锛岃櫧鐒惰В鍐充簡鐩綍鍜岀被闂磋皟鐢ㄧ瓑绛変竴澶у爢鎶ラ敊锛屼絾杩樻湁涓€浜涙姤閿欎笉鐭ラ亾鎬庝箞瑙e喅锛屾瘮濡備笅闈㈣繖涓細

鎶€鏈浘鐗? src=

鏈€鍚庡啓浜嗕釜绠€鍗曟牱渚嬶細

package test;
?
public class MyGroup {
?
        /*@ public instance model non_null int id;
      @ public instance model non_null int[] people;
      @*/
?
    private int[] people_;
    private int id_;
?
    public MyGroup(int id) {
        people_ = new int[100];
        id_ = id;
    }
?
    //@ ensures 
esult == id;
    public /*@pure@*/ int getId() {
        return id_;
    }
?
    /*@ also
  @ public normal_behavior
  @ requires obj != null && obj instanceof MyGroup;
  @ assignable 
othing;
  @ ensures 
esult == (((MyGroup) obj).getId() == id);
  @ also
  @ public normal_behavior
?
  @ requires obj == null || !(obj instanceof MyGroup);
  @ assignable 
othing;
  @ ensures 
esult == false;
  @*/
    public /*@pure@*/ boolean equals(Object obj) {
        if (!(obj instanceof MyGroup)) {
            return false;
        }
        return (((MyGroup) obj).getId() == id_);
    }
}

缁撴灉濡備笅锛?/span>

鎶€鏈浘鐗? src=

缁撳悎鎴戠殑绠€鍗曟牱渚嬪拰澶т浆浠殑姝g粡鏍蜂緥锛屽彲浠ョ湅鍑虹敓鎴愬ぇ閮ㄥ垎鏄壒娈婃儏鍐?杈圭晫鏁版嵁銆傝櫧鐒惰窇鍑烘潵浜嗭紝浣嗕笉鐭ラ亾涓轰粈涔坈onstructor娴嬭瘯涓嶉€氳繃锛燂紵锛熸€讳箣jmlunitng瀹炲湪鏄竴鍓骞存病缁存姢鐨勬牱瀛愶紝鎰熻瀹炵敤鎬у緢灏忥紙閫?/span>

 

3.鎸夌収浣滀笟姊崇悊鑷繁鐨勬灦鏋勮璁?/span>锛岀壒鍒垎鏋愯嚜宸辩殑妯″瀷鏋勫缓绛栫暐

绗竴娆′綔涓?/span>锛氱被鏋勯€犱笌jml鐩稿悓锛屽鍣ㄧ粺涓€浣跨敤ArrayList锛屾悳绱㈢畻娉曚娇鐢╠fs銆?/span>

鎶€鏈浘鐗? src=

绗簩娆′綔涓?/span>锛氬姞鍏roup绫伙紝瀹瑰櫒浠嶇劧鐢ˋrrayList锛坆ug淇涓凡淇敼锛夛紝鎼滅储绠楁硶浣跨敤骞舵煡闆嗐€?/span>

鎶€鏈浘鐗? src=

绗笁娆′綔涓?/span>锛氬鍔燫elationship绫伙紝鐢ㄤ簬澶勭悊minPath銆傚鍣ㄥ鍔燞ashMap銆俶inpath浣跨敤bellman-ford绠楁硶锛宻tronglinked鐢ㄤ袱娆fs锛宐locksum鐢ㄥ苟鏌ラ泦銆?/span>

鎶€鏈浘鐗? src=

鎬讳綋鏉ヨ鏄寜jml鏉ヨ璁℃灦鏋勩€?/span>

 

4.鎸夌収浣滀笟鍒嗘瀽浠g爜瀹炵幇鐨刡ug鍜屼慨澶嶆儏鍐?/span>

绗竴娆′綔涓?/span>锛氬己娴?鍒嗭紝鍑虹幇浜嗚秴鏃跺拰bug锛屾妸isCircle浠巄fs鏀规垚骞舵煡闆嗗悗杩囦簡銆?/span>

绗簩娆′綔涓?/span>锛氳繕鏄己娴嬩腑鍑虹幇浜嗚秴鏃跺拰bug锛屽崄鍒嗛毦杩?(

绗竴涓秴鏃跺師鍥犳槸contains鍜実etperson閮芥槸閲嶅鐢ㄧ殑锛屽叏閮ㄦ敼鎺夊悗杩囦簡鍥涗釜鐐广€?/span>

绗簩涓秴鏃跺師鍥犳槸getPerson鐢ˋrrayList锛屽湪璁捐棰戠箒鏌ユ壘鐨勫湴鏂归兘澧炲姞浜咹ashMap涔嬪悗鍙樻垚WA銆?/span>

绗竴涓猙ug鏄痳elationSum鐨凧ML鐞嗚В閿欎簡銆傚洜涓鸿瘎娴嬫彁绀烘槸expect 1 get 0锛屼竴鐩翠互涓烘槸isCircle骞舵煡闆嗗啓閿欎簡锛宒e浜嗗彂鐜板啓鐨勫畬鍏ㄦ病閿欍€備箣鍚庯紝鍦╣ithub涓婂彂鐜颁簡澶т浆鐨勮瘎娴嬫満锛堟劅璋㈠ぇ浣級锛岃嚜宸变慨鏀逛簡涓嬶紝鐬棿鍙戠幇浜哹ug……鍏蜂綋闂鏄病鎶婅嚜宸卞拰鑷繁鐨勫叧绯荤畻杩涘幓锛岃€屼笖绠楃殑涓嶆槸group閲岀殑鏄墍鏈変汉鐨剆um銆?/span>

绗簩涓猙ug鏄繕浜嗚€冭檻<1111銆?/span>

绗笁娆′綔涓?/span>锛氬己娴嬫湁bug锛岃繕娌′慨澶嶏紝浣嗘瘮璧峰墠涓ゆ鐨勬儴鐘惰繕鏄湁杩涙鐨勩€俶inpath鐢ㄤ簡Bellman-Ford銆俿tronglinked鐢ㄤ簡dfs锛屾湁bug……

绠楁硶鏁堢巼鍜孞ML缁嗚妭鏂归潰閮藉嚭鐜颁簡涓ラ噸闂锛屽湪debug杩囩▼涓姞娣变簡瀵笿ML鐨勭悊瑙c€?/span>

 

5.闃愯堪瀵硅鏍兼挵鍐欏拰鐞嗚В涓婄殑蹇冨緱浣撲細

閫氳繃鍓嶄袱娆′綔涓氾紝鍙戠幇鐓х潃jml缈昏瘧缁濆浼氬嚭鐜颁弗閲嶉棶棰樸€侸ML鍙互璁╀唬鐮佺紪鍐欑湅璧锋潵闈炲父鐩存帴锛屼絾鍏跺疄鍙捣鍒颁弗鏍艰鑼冪殑浣滅敤锛屾€ц兘鍜屾灦鏋勬柟闈㈤渶瑕佸疄鐜拌€呰嚜宸辨繁鍏ユ€濊€冦€傚彟澶栵紝褰曟挱瑙嗛閲屾彁鍒扮殑鏋舵瀯闂鎴戝湪浣滀笟杩囩▼涓病鏈夎€冭檻杩囷紝鐜板湪鏉ョ湅Network绫荤‘瀹炲疄鐜颁簡澶鍔熻兘锛屽簲璇ヨ繘琛屾娊璞″拰鍒嗚В锛屼緥濡傛妸绠楁硶鏀惧湪鍗曠嫭鐨勭被閲屻€傚叾瀹炴湰鍗曞厓闅惧害姣旀垜鎯宠薄鐨勮浣庯紙铏界劧鐢变簬鑷繁鑿滃墠涓ゆ浣滀笟杩樻槸宕╀簡锛夛紝鍥犱负鍩烘湰娌℃湁娑夊強鍐橨ML锛屾劅瑙夊姪鏁欑殑宸ヤ綔閲忔洿澶AQ 浠庡疄楠屾潵鐪嬶紝鎴戝湪鍐橨ML鍜屾鏌ML姝g‘鎬ф柟闈㈣兘鍔涜繕闇€瑕佹彁鍗囥€?/span>

以上是关于OO绗笁鍗曞厓鎬荤粨的主要内容,如果未能解决你的问题,请参考以下文章

绗崄浜屽懆璇剧▼鎬荤粨

JQuery甯哥敤鏂规硶鎬荤粨

0527Sprint鎬荤粨锛岃涔︾瑪璁颁笌鎻愰棶

鍗曞厓娴嬭瘯锛?锛岄泦鎴愭祴璇曪細0

Java鎬荤粨

20191324銆婁俊鎭畨鍏ㄤ笓涓氬璁恒€嬬浜屽懆瀛︿範鎬荤粨