Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 9th, 2009, 04:40 PM
Authorized User
 
Join Date: Mar 2009
Posts: 75
Thanks: 16
Thanked 1 Time in 1 Post
Default Question regarding Article and ArticleDetails class

Why there is a need of ArticleDetails class with all defined fields.
If in article class the same fields are defined once again with all getters/setters?

Why we can't also use ArticleDetails class as field inside Article class?
 
Old April 9th, 2009, 07:01 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

The question you are askin goes to the very heart of why n-tier applications exist in the first place.

Think about what an article actually is in real life. It is a thing with properties such as an author, a body, and abstract, a publish date, and so on. It is also a thing that can have actions performed on it, such as being written, saved, updated, thrown away, and so on.

Now, think about what an article is to your database. It is a table with rows and columns, nothing more.

So, in effect, an article "exists" in two different forms -- as a data-storage conceptual table construct, and as a real-world object.

The idea behind an n-tier application is that it is easier for programmers, being human and all, to deal with real-world objects rather than rowns and columns. So, we create layers in our programs to translate from one form to the other.

Those layers need to have classes that can represent what an "article" means in that layer. In a data access layer, you have an ArticleDetails class that represents the columns of the table and the data within them. And in the business logic layer, you have an Article class that represents the properties of the real world object.

Once these layers are in place, we can build our pages, using the BLL to treat an Article as a real world object. We can evaluate and set its properties, call its methods, and so on, without ever having to think about "rows" and "columns" at all.

Getting back to your real-world question -- do you need to do it this way? Of course not. If you feel comfortable doing so, you are free to flatten the BLL and DAL into a single layer if you like. That way, you wouldn't need an ArticleDetails class. You could just put all of that data access logic right in the same class as the Article's properties and methods if you want.

However, most programmers find it easier and more natural to do it as seperate layers, so that the data access logic is abstracted away, and so we don't have to think about it.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
The Following User Says Thank You to Lee Dumond For This Useful Post:
yevi (April 10th, 2009)
 
Old April 10th, 2009, 02:59 AM
Authorized User
 
Join Date: Mar 2009
Posts: 75
Thanks: 16
Thanked 1 Time in 1 Post
Default

Thank you for this great answer.

I still need to clarify one more issue:
If I put in Article class a field ArticleDetails articleDetails = new ArticleDetails();
will it brake n-tier structure?

I also think that n-tier is the the right way to develop applications, but duplication of code (same fields getters/setter both in Article and ArticleDetails classes) bother me.
 
Old April 10th, 2009, 01:10 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

I find it somewhat difficult to answer that, because I cannot think of a reason why this would be of any benefit.

Maybe you could explain what you hope to gain from doing that.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old April 10th, 2009, 02:38 PM
Authorized User
 
Join Date: Mar 2009
Posts: 75
Thanks: 16
Thanked 1 Time in 1 Post
Default

I'll try to explain.

I don't like that Article class has the same fields as the ArticleDetails:
Code:
 private DateTime _addedDate = DateTime.Now;
        public DateTime AddedDate
        {
            get { return _addedDate; }
            set { _addedDate = value; }
        }

        private string _addedBy = "";
        public string AddedBy
        {
            get { return _addedBy; }
            set { _addedBy = value; }
        }

        private int _categoryID = 0;
        public int CategoryID
        {
            get { return _categoryID; }
            set { _categoryID = value; }
        }

        private string _categoryTitle = "";
        public string CategoryTitle
        {
            get { return _categoryTitle; }
            set { _categoryTitle = value; }
        }

        private string _title = "";
        public string Title
        {
            get { return _title; }
            set { _title = value; }
        }

        private string _abstract = "";
        public string Abstract
        {
            get { return _abstract; }
            set { _abstract = value; }
        }

        private string _body = "";
        public string Body
        {
            get { return _body; }
            set { _body = value; }
        }

        private string _country = "";
        public string Country
        {
            get { return _country; }
            set { _country = value; }
        }

        private string _state = "";
        public string State
        {
            get { return _state; }
            set { _state = value; }
        }

        private string _city = "";
        public string City
        {
            get { return _city; }
            set { _city = value; }
        }

        private DateTime _releaseDate = DateTime.Now;
        public DateTime ReleaseDate
        {
            get { return _releaseDate; }
            set { _releaseDate = value; }
        }

        private DateTime _expireDate = DateTime.MaxValue;
        public DateTime ExpireDate
        {
            get { return _expireDate; }
            set { _expireDate = value; }
        }

        private bool _approved = true;
        public bool Approved
        {
            get { return _approved; }
            set { _approved = value; }
        }

        private bool _listed = true;
        public bool Listed
        {
            get { return _listed; }
            set { _listed = value; }
        }

        private bool _commentsEnabled = true;
        public bool CommentsEnabled
        {
            get { return _commentsEnabled; }
            set { _commentsEnabled = value; }
        }

        private bool _onlyForMembers = true;
        public bool OnlyForMembers
        {
            get { return _onlyForMembers; }
            set { _onlyForMembers = value; }
        }

        private int _viewCount = 0;
        public int ViewCount
        {
            get { return _viewCount; }
            set { _viewCount = value; }
        }

        private int _votes = 0;
        public int Votes
        {
            get { return _votes; }
            set { _votes = value; }
        }

        private int _totalRating = 0;
        public int TotalRating
        {
            get { return _totalRating; }
            set { _totalRating = value; }
        }
    }
...
If I insert ArticleDetails as field inside Article class i will have the same fields without the need to define them one again.
Doing so of course will require to modify some of the methods, that I modify anyway because I've decided to remove statics from all business layer classes(I don't know why but i don't like to have so many static methods I prefer to call methods object-wise)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about BizObject class. yevi BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 10 April 16th, 2009 01:12 PM
HEADS-UP: Error in Article class Lee Dumond BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 May 1st, 2008 11:28 PM
public article - public articledetails _keysersoze_ BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 September 8th, 2007 08:38 AM
question about sub New() in class hertendreef ASP.NET 2.0 Basics 7 January 3rd, 2007 02:10 PM
Error in BLL.Article.Article.cs drohm BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 August 14th, 2006 09:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.