Last active
December 31, 2015 14:49
-
-
Save azusa/8002763 to your computer and use it in GitHub Desktop.
Singletonの例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jp.fieldnotes.sample.singleton; | |
import java.math.BigDecimal; | |
/*: | |
* 消費税率を返します。実際にはデータベースのマスター等から期間に応じて適用税率を返すことになります。<br/> | |
* 諸外国にある小数点以下の桁を含む税率には対応しましたが、軽減税率はちょっと本題を外れるのでオミット。 | |
*/ | |
public class TaxSingleton { | |
private static TaxSingleton target = new TaxSingleton(); | |
private static final BigDecimal rate = new BigDecimal("5"); | |
private TaxSingleton(){ | |
} | |
public BigDecimal getRate(){ | |
return rate; | |
} | |
public static TaxSingleton getInstance(){ | |
return target; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment