Application Design - Common Parameter

L

Lza

Hey,

I have a system that I am trying to design, it contains news articles,
events, etc... There is class representing articles, one representing
events, etc...

Articles or events can be active or inactive, so I can do a query to
return all active articles, all articles or all inactive articles.

The question that I have is what would be the best way to design this.
Right now I have each method (such as recentArticles,
featuredArticles, etc...) taking an 'active' parameter. This requires
littering
the code with method calls taking this parameter.

I have also thought about setting a class variable on the models to set

whether active/inactive/all articles are returned, so that anytime you
want to set the type returned you set this class variable and then call

your functions (recentArticles, etc...).

What I would like to know is if there are any suggestions as to a good
practice to follow in how to implement this functionality, one of the
ways I have stated or some other way that I haven't considered.

I hope I have been clear. Thanks for the help in advance.
 
C

Chris Uppal

Lza said:
Right now I have each method (such as recentArticles,
featuredArticles, etc...) taking an 'active' parameter. This requires
littering
the code with method calls taking this parameter.

Maybe you could have a general Query (or Filter) object which contains the data
necessary to select the articles of interest. You would pass those around as
the parameter to methods, instead of encoding the query as the combination of
the method's name (e.g. recentArticles()) and parameters. That Query object
would include flag(s) to say whether active or innactive articles should be
included.

-- chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top