Self Encapsulate Field(自封装字段)
生活随笔
收集整理的這篇文章主要介紹了
Self Encapsulate Field(自封装字段)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
直接訪問(wèn)一個(gè)字段,但與字段之間的耦合關(guān)系逐漸變得笨拙
private int low; private int high;boolean includes(int arg) {return arg >= low && arg <= high; }重構(gòu):為這個(gè)字段建立get/set函數(shù),并以這些函數(shù)訪問(wèn)字段
private int low; private int high;public int getLow() {return low; }public int getHigh() {return high; }public boolean includes(int arg) {return arg >= getLow() && arg <= getHeigh(); }總結(jié)
以上是生活随笔為你收集整理的Self Encapsulate Field(自封装字段)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Replace Delegation w
- 下一篇: Eclipse相关