Question about Categories & Articles

Last post 03-02-2009 5:37 PM by avmood. 6 replies.

Sort Posts:

  • Question about Categories & Articles

    02-27-2009, 3:57 PM
    • Member
      459 point Member
    • avmood
    • Member since 02-17-2008, 12:20 PM
    • Posts 848

     Hi, I just started learning the BLL and DAL and got a question about the BLL. In the Article class and Category class, I see the following

    Article - public static List<Article> GetArticles(bool publishedOnly, int categoryID)

    Category- public List<Article> AllArticles

    Why do we need public List<Article>AllArticles in the Category class, can we just retrieve all the articles using the List<article>GetArticles in the article class?

  • Re: Question about Categories & Articles

    02-28-2009, 12:55 AM
    • Participant
      1,014 point Participant
    • chandu2chandu1
    • Member since 03-23-2007, 6:06 AM
    • Bangalore, India
    • Posts 233

    Hi Avmood,

    It's very simple.  This is nothing but the feature of the generics released in asp.net 2.0.  However your GetArticles will return the List of the Article class.  Instead you can say this as the you will return a strongly typed Articles while you make a call to GetArticles method.  If you are even much enthusiastic about this, just google the Generics in C#.  Anyway, your subject "Question about Categories & Articles" will make your question less readable.  Always have a better subject line instead that will make the attentions of the people at a single shot.

    Imagination is more important than knowledge..
    [Albert Einstein]

    Regards,
    Chandu

    My Blog
  • Re: Question about Categories & Articles

    02-28-2009, 1:00 AM

    the main deference is the implementation inside each function, the first one returns the published articles inside that category, the second one returns all the articles published/unpublished inside the category, I know it's a little bit cofusing, but just take the concept and deal with it as per your needs, i've used this kit and modified to much in it to fit my needs..

  • Re: Question about Categories & Articles

    03-02-2009, 12:04 PM
    • Member
      459 point Member
    • avmood
    • Member since 02-17-2008, 12:20 PM
    • Posts 848

    Hi chandu2chandu1, I think you misundertand my question. I understand what generic types are for. My question is why we need the method GetAllArticle in the Categories class, since we there is already another method call GetArticle(int category) in the class Article?

  • Re: Question about Categories & Articles

    03-02-2009, 12:08 PM
    • Member
      459 point Member
    • avmood
    • Member since 02-17-2008, 12:20 PM
    • Posts 848

     Actually what I want to know is what is the benefit of implementing an GetArticle in the Article class and another one in the Category class, isn't it duplicate?

  • Re: Question about Categories & Articles

    03-02-2009, 1:44 PM
    Answer
    • Contributor
      6,366 point Contributor
    • Lee Dumond
    • Member since 11-03-2004, 2:51 PM
    • Decatur, IL USA
    • Posts 1,168

     Actually, the short answer is: simple flexibility and convenience.

     The AllArticles property of Category is merely a read-only property which actually uses the Article.GetArticles method to populate its value. That way, if you need to get a list of all articles that belong to a certain category, you can do this:

    List<Article> articlesInMyCategory = myCategory.AllArticles;

    instead of this:

    List<Article> articlesInMyCategory = Article.GetArticles(myCategory.ID, 0, BizObject.MAXROWS);

    If you look closely, you will notice that the AllArticles property is never actually used throughout the entire application, but it's there anyway. Is this duplicative? Yes, it is. But, it also extends the functionality of the API by giving you two different ways of obtaining the same result, which is a common programming practice.

    You will note that the Author has this kind of "duplication" in several other places. For example, in the Articles class:

    public bool Delete()
    public static bool DeleteArticle(int id)

    Why have both an instance method and a static method that do exactly the same thing? Again, it offers an option. That's why it is a common programming practice to provide instance methods that mirror the static methods in a class. You will notice in every business object in this application, there are instance methods that reference corresponding static methods, even though most of the instance methods are never used.

    Whether you feel it is useful to offer this kind of flexibility in an API is basically a programming design choice. Many do it, others don't.

    Hope that makes sense.

  • Re: Question about Categories & Articles

    03-02-2009, 5:37 PM
    • Member
      459 point Member
    • avmood
    • Member since 02-17-2008, 12:20 PM
    • Posts 848

     Thanks Lee, now I understand it completely.

Page 1 of 1 (7 items)