• Post Reply Bookmark Topic Watch Topic
  • New Topic

static factory method diavadvantage  RSS feed

 
praveen kumaar
Ranch Hand
Posts: 461
22
Android Chrome Eclipse IDE Google App Engine Java Notepad Oracle Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am reading effective java...

i dont understand the second disadvantage of static factory methods that their it is difficult to readily differentiate the 2 static factory methods..
what does it mean?
 
Campbell Ritchie
Marshal
Posts: 55761
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have my copy with me; please give the page number and please copy a bit more of what Bloch says.
 
praveen kumaar
Ranch Hand
Posts: 461
22
Android Chrome Eclipse IDE Google App Engine Java Notepad Oracle Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A second disadvantage of static factory methods is that they are not
readily distinguishable from other static methods. They do not stand out in API
documentation in the way that constructors do, so it can be difficult to figure out
how to instantiate a class that provides static factory methods instead of constructors.
The Javadoc tool may someday draw attention to static factory methods. In
the meantime, you can reduce this disadvantage by drawing attention to static factories
in class or interface comments, and by adhering to common naming conventions.
Here are some common names for static factory methods:
 
praveen kumaar
Ranch Hand
Posts: 461
22
Android Chrome Eclipse IDE Google App Engine Java Notepad Oracle Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:I don't have my copy with me; please give the page number and please copy a bit more of what Bloch says.


page no-10
 
Campbell Ritchie
Marshal
Posts: 55761
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that is very clear. If you have many methods, it can be difficult to work out which is the factory method by reading the API. Look for methods with names like getInstance, newInstance, of and valueOf. Some classes make the search slightly easier by the simple expedient of not exposing a constructor. This is one. You can't create an instance from a constructor, so you know you have to find a factory method. Searching for factory only yields one hit, in the from method, but there are several methods with names starting of. Once you know you are looking for a factory method, you can find it easily by looking for methods with names starting of, or searching for the word instance.
 
Liutauras Vilda
Marshal
Posts: 4657
319
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, that paragraph says what's actually all about. I'm afraid that could be difficult to re-phrase.
Joshua also mentions, that it isn't necessarily to read the book item by item, you can skip the ones which doesn't say a lot to you now and come back later once you get more experience. That book isn't for beginners, although you can find good advises on easier topics.
I'd say don't worry about it too much and move onto other items
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!