• Post Reply Bookmark Topic Watch Topic
  • New Topic

implementing convenience methods  RSS feed

 
bart zagers
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example when we have a MailService interface


our typical implementation would be something like:


Is it a good idea to implement the first method in terms of the second?
Is the singletonList() a good way construct a List in this situation or are there better ways to construct it?
 
Manuel Leiria
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see any advantage on that!
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I love the ranch because I learn something every day. I'd never looked at the singletonList() method. It looks useful enough for what you're doing, even if the name is terrible. Fortunately it has nothing to do with the Singleton pattern.

Convenience methods like that are a bit controversial. They add noise to an API and this one doesn't really save the client much effort or complexity. Here's a writeup with some Pros and Cons. I think I defer creating convenience methods until I feel some pain calling the original method. Of course if the code is for somebody else to call, you may never feel the pain.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!