---
title: "静态方法设计探讨"
author: "harrison2010"
date: "2008-11-19T14:49:22Z"
tags: []
categories: ["企业架构"]
slug: "untitled"
draft: false
lastmod: "2008-11-19T14:50:17Z"
id: 270376
url: "https://harrison2010.iteye.com/blog/270376"
---

一个公用的类，提供一些常用的办法，这里我就拿把123456格式化成123，456这样的方法来说吧。
方案一：

```java
public class FormatterUtil {
	public String formatterString(String money){
		//.....
		return money;
	}
}

```

比如在servlet中使用，通过spring依赖注入保持FormatterUtil的单例

```java
private FormatterUtil formatterUtil;

	public void execute(){
		String money ="123456";
		formatterUtil.formatterString(money);
	}
	
	
	public FormatterUtil getFormatterUtil() {
		return formatterUtil;
	}

	public void setFormatterUtil(FormatterUtil formatterUtil) {
		this.formatterUtil = formatterUtil;
	}

```

方案二:

```java
public class FormatterUtil {
	public static String formatterString(String money){
		//.....
		return money;
	}

}

```

使用:

```java
public void execute(){
		String money ="123456";
		FormatterUtil.formatterString(money);
	}

```

util类的内容很多，或者是类似的manager类。
大家认为哪一种解决方案好，或者更好的解决办法。