Coo*_*ans 1 java refactoring design-patterns
我目前正在重构一些旧代码.我正在寻找有关最佳设计模式的说明.我在考虑工厂模式,但我不确定这是不是最好的方式.
所以这里是伪代码的简要概述.Foo类具有核心业务逻辑.
Class Foo{
private List<Things> stuff;
private static Integer count;
//getter setter for stuff
public Foo(List<Things> stuff){
this.stuff = stuff;
this.count=1;
}
//the following 3 methods are 90% similar
public List<Newthings> doSomeThingFirst(){
//uses the list stuff and also increments the static member count for each entry in List<NewThings> based on certain conditions
}
public List<Newthings> doSomethingSecond(){
//uses the list stuff and also increments the static member count for each entry in List<NewThings> based on certain conditions
}
public List<Newthings> doSomethingThird(){
//uses the list stuff and also increments the static member count for each entry in List<NewThings> based on certain conditions
}
//in the future there may be doSomethingFourth(), doSomethingFifth() ... etc.
}
The caller of class Foo looks something like below.
Class SomeServiceImpl{
public List<Things> getAllFoo(List<Things> stuff){
Map<Integer,NewThings> fooList = new HashMap<Integer,NewThings>();
Foo foo = new Foo(stuff);
fooList.put(1,foo.doSomeThingFirst());
fooList.put(2,foo.doSomeThingSecond());
fooList.put(3,foo.doSomeThingThird());
return new ArrayList<Things>(fooList.values());
}
}
Run Code Online (Sandbox Code Playgroud)
让我知道您如何认为此代码应该重构为可维护性和重用,或者它是否正常?
感谢您的投入.
// the following 3 methods are 90% similar
Run Code Online (Sandbox Code Playgroud)
由于您没有提供实际代码,因此这是您要考虑的部分.
| 归档时间: |
|
| 查看次数: |
346 次 |
| 最近记录: |