我有采取不同的输入方法调用,即:构建通用过滤器参数输入接口?
public Authors GetAuthors(string name, string sortBy, string sortDir, int startRow, int numRow)
{
// Get authors based on filters
}
public Books GetBooks(string id, string year, string sortBy, string sorDir, int startRow, int numRow)
{
// Get books based on filters
}
我打算去改变它,这样的过滤器是对象,即:
public Authors GetAuthors(GetAuthorsFilters filters)
{
// Get authors based on filters
}
public Books GetBooks(GetBooksFilters filters)
{
// Get books based on filters
}
但是许多过滤器跨越很常见方法,我想为此构建一个通用接口(即IFilter
),它可以接受不同的过滤对象,但不知道从哪里开始。任何建议或建议?
谢谢。
规范模式的完美例证。检查此链接:http://devlicio.us/blogs/jeff_perrin/archive/2006/12/13/the-specification-pattern.aspx – Chandu
感谢Cybernate,我会检查链接。 – Saxman