为别人提供方法工具类的时候传递参数有什么特别的要求吗?

昨天花时间为别人写了个工具类,作用就是生成Rss文件,具体代码如下:

public class RssBuilder {
 private SyndFeed feed;
 private List entries;
 private SyndEntry entry ;
 public RssBuilder(){
  feed = new SyndFeedImpl();
  feed.setFeedType("rss_2.0");
  entries = new ArrayList();
 }
 
 
 public void createChannelImage(String title,String link,String url,String description) throws Exception{
  SyndImage image = new SyndImageImpl();
  image.setTitle(title);
  image.setLink(link);
  image.setUrl(url);
  image.setDescription(description);
  feed.setImage(image);
 }
 
 /**
  * 创建一个频道
  * @param title 频道标题
  * @param link 频道对应的连接
  * @param description 频道描述
  * @param language 频道所用语言
  * @param pubDate 频道发布时期
  * @param copyright 版权所有
  * @throws Exception
  */
 public void createChannel(String title,String link,String description,String language,Date pubDate,String copyright) throws Exception{
  feed.setTitle(title);
  feed.setLink(link);
  feed.setDescription(description);
  feed.setLanguage(language);
  feed.setPublishedDate(pubDate);
  feed.setCopyright(copyright);
 }
 

 
 /**
  * 添加新闻子项
  * @param title 标题
  * @param link 连接地址
  * @param description 简单描述
  * @param pubDate 发布日期
  * @param category 所属范围
  * @param author 发布作者
  * @throws Exception
  */
 public void createItems(String title,String link,String description,Date pubDate,String category,String author) throws Exception {
  entry = new SyndEntryImpl();
  //设置新闻标题
  entry.setTitle(title);
  //设置新闻的连接地址
  entry.setLink(link);
  //设置新闻简介
  SyndContent content = new SyndContentImpl();
  content.setType("text/plain");
  content.setValue(description);
  entry.setDescription(content);
  //设置发布时间
  entry.setPublishedDate(pubDate);
  //设置频道所属的范围
  SyndCategory cate = new SyndCategoryImpl();
  cate.setName(category);
  List cateList = new ArrayList();
  cateList.add(cate);
  entry.setCategories(cateList);
  //设置作者
  entry.setAuthor(author);
  //将新闻项添加至数组中
  entries.add(entry);
 }
 
 /**
  * 添加新闻子项
  * @param title 标题
  * @param link 连接地址
  * @param description 简单描述
  * @param pubDate 发布日期
  * @param category 所属范围
  * @param author 发布作者
  * @param enclosure 流媒体播放文件地址
  * @throws Exception
  */
 public void createItems(String title,String link,String description,Date pubDate,String category,String author,String enclosure) throws Exception {
  entry = new SyndEntryImpl();
  //设置新闻标题
  entry.setTitle(title);
  //设置新闻的连接地址
  entry.setLink(link);
  //设置新闻简介
  SyndContent content = new SyndContentImpl();
  content.setValue(description);
  entry.setDescription(content);
  //设置发布时间
  entry.setPublishedDate(pubDate);
  //设置频道所属的范围
  SyndCategory cate = new SyndCategoryImpl();
  cate.setName(category);
  List cateList = new ArrayList();
  cateList.add(cate);
  entry.setCategories(cateList);
  //设置作者
  entry.setAuthor(author);
  //设置流媒体播放文件
  SyndEnclosure en = new SyndEnclosureImpl();
  en.setUrl(enclosure);
  List enList = new ArrayList();
  enList.add(en);
  entry.setEnclosures(enList);
  //将新闻项添加至数组中
  entries.add(entry);
 }
 /**
  * 生成XML文件
  * @param filePath 文件保存路径和名称
  * @throws Exception
  */
 public void buildChannel(String filePath) throws Exception {
  feed.setEntries(entries);
  SyndFeedOutput output = new SyndFeedOutput();
  Writer writer;
  writer = new OutputStreamWriter(new FileOutputStream(filePath), "UTF-8");
  output.output(feed, writer); 
 }
}

 

  让我们的项目负责人看了,他要我把createItems()方法中的多个参数再封装一个类,让用户传的时候只传一个包含这个类的List对象,想来想去就是不明白,为什么要这样呢?

  按照我现在的写法的话,别人用的时候也不用再写什么特别的类啦,只用把自己从数据库里查询出来的结果的对象以参数的形式传递过来就可以啦,这样不就更简单啦。

  为什么一定要传一个List对象呢?

  写工具类的时候有什么特别的要求吗?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值