advantage:
1st. unlike constructors, they have names.
2nd. unlike constructors,they are not required to create a new object each time they’re invoked.
3rd. unlike constructors,they can return an object of any subtype of their return type.
提供了灵活性,可以隐藏实现细节。可以根据不同的参数采用不同的实现....
4th. that they reduce the verbosity of creating parameterized type instances.
disadvantage:
1st.providing only static factory methods is that
classes without public or protected constructors cannot be subclassed.
2nd.they are not readily distinguishable from other static methods.
解决办法:1、注释 2、尽量采用通用的命名,比如ValueOf、of、getInstance、newInstance、get[i]Type[/i]、new[i]Type[/i]
1st. unlike constructors, they have names.
2nd. unlike constructors,they are not required to create a new object each time they’re invoked.
3rd. unlike constructors,they can return an object of any subtype of their return type.
提供了灵活性,可以隐藏实现细节。可以根据不同的参数采用不同的实现....
4th. that they reduce the verbosity of creating parameterized type instances.
disadvantage:
1st.providing only static factory methods is that
classes without public or protected constructors cannot be subclassed.
2nd.they are not readily distinguishable from other static methods.
解决办法:1、注释 2、尽量采用通用的命名,比如ValueOf、of、getInstance、newInstance、get[i]Type[/i]、new[i]Type[/i]
本文探讨了工厂方法在软件设计中的优势与劣势。优势包括命名明确、减少实例创建冗余及提供子类型灵活性等;劣势则涉及无法进行子类化及区分度不高等问题,并提出了解决方案。
126

被折叠的 条评论
为什么被折叠?



