简体   繁体   中英

Static factory methods in effective java

In Effective Java , Item 1, it says that the static factory methods made the Collections framework much smaller than it would have been. Could someone please explain how ? I can't understand how the following is possible just because of using static factory methods ? I mean we still have to implement those separate implementations don't we ?

The Collections Framework API is much smaller than it would have been had it exported thirty-two separate public classes, one for each convenience implementation.

By "smaller" they mean "less classes".

Instead of providing lots of classes for each variation of implementation, instead factory methods have been provided that return such implementations without the need to have their classes declared as top-level classes (less "class bloat").

I think the meaning here is that there's only core implementations in java collections API, if you need synchronisation, etc "wrappers" are provided by static factories.

So there's 8 implementations and without "wrappers" there would be more (size gain).

See http://docs.oracle.com/javase/7/docs/technotes/guides/collections/overview.html for more details

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM