0
我必須維護一個代碼,爲類中的最終靜態變量添加更多的靈活性。最終靜態屬性更改..任何想法或方法?
該變量不再是一個全局常量,可以改變。
問題是該類在一個公共庫中,並在不同的項目中使用。
您是否有比將公共庫中的類代碼複製並粘貼到特定應用程序並重構它更好的方法或設計模式?
例子:
Commons項目
Class CommonClass {
public final static var globalSomething = somethingGlobal;
public static method(){ //CommonClass.globalSomething is used here}
}
在我的應用程序(和引用公共其他應用程序),我們可以使用靜態屬性,並調用方法:
--->var b = CommonClass.somethingGlobal;
--->var c = CommonClass.method() //we know that CommonClass.globalSomething is used here
點期望:
- 能力改變CommonClass.somethingGlobal在我的應用程序,並採取呼叫CommonClass.method()這些變化
- 我可以修改(添加方法)中常見的類,但我必須保持相同的初始行爲(不要打破其他項目引用的公共項目)
你在用什麼IDE?在Eclipse和Intellij中有一些很棒的重構。 – david99world
你的問題有點含糊。你可以添加一些代碼,或嘗試reqording你的qeustion? –
我也不明白你的問題。剛刪除'final'修飾符,構建一個新版本的庫並在其他項目中使用它會出現什麼問題? –