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 August 19th, 2009, 02:56 PM
Authorized User
 
Join Date: Aug 2009
Posts: 12
Thanks: 5
Thanked 0 Times in 0 Posts
Default BLL Article Instance Methods

I am going over the Article class and have questions about the instance methods.

The Delete method:
Code:
public bool Delete()
{
	bool success = Article.DeleteArticle(this.ID);
	if (success)
		this.ID = 0;
	return success;
}
Why do we just set the ID property to zero and not reset all properties to their original values if the deletion is successful? Imagine that we have an Article object with all the information (holding the comments and everything) and we call the delete method. We would still have a lot of information in the object that is not really reflecting the record in the database. Is there a purpose for this?

The IncrementViewCount method:
Code:
public bool IncrementViewCount()
{
	return Article.IncrementArticleViewCount(this.ID);
}
Why don't we update the object's ViewCount property? So we increment the ViewCount in the database by 1, but the property in the object is not reflecting that value. However, in the Approve method we do update the object's Approved property. This seems at least inconsistent.

The Rate method:
Code:
public bool Rate(int rating)
{
	return Article.RateArticle(this.ID, rating);
}
Same thing as with the IncrementViewCount method. Why don't we update the TotalRating property?

Anyone else has found this awkward?

Thanks for any light on this.

Last edited by alfinmass; August 19th, 2009 at 02:58 PM.. Reason: Used the wrong slash in the closing code tags
 
Old August 19th, 2009, 04:10 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

You will notice that in some of the static methods that are called by these various instance methods, the cache is purged, and in others it is not.

That should give you a big clue.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}

Last edited by Lee Dumond; August 19th, 2009 at 06:05 PM.. Reason: got some terms mixed up ;)
The Following User Says Thank You to Lee Dumond For This Useful Post:
alfinmass (August 19th, 2009)
 
Old August 19th, 2009, 05:54 PM
Authorized User
 
Join Date: Aug 2009
Posts: 12
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Hi Lee,

thanks as usual for answering my posts. First, I like the "purged is cached", hahahahahahaha Don't let your brain go so fast man...

Purging the cache will just cause the next article to be created to get fresh data from the database. My point was on what happens to the objects that are already created, since they are left holding information that is no longer valid.

For example let us consider the delete method. Let us say that you have filled the Article object fields with all the appropriate data and then you call the instance method Delete(). That will delete the article in the database, and the comments because of the cascading foreign key setup, but the Article object will still have the same values that are no longer on the database on its fields. The only thing that has changed is the _id field which now has a value of 0.

I don't know if filling up the fields before calling the delete method would be a common use of the object, but we cannot assume that it is not, can we? So shouldn't we reset all the fields to their original values when we call the delete method so we have an 'empty' article and all the related objects are orphaned so the garbage collector can collect them?

In the case of the rating and incrementing views is more like the object field would hold the wrong rate or view count after calling those methods.

Again it is not so much what happens when we try to load the data again, but what happens to the data we currently have loaded in the object.

Thanks. :-)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Why do we need to maintain "static" methods in the Article.cs? Jyothi_23 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 April 13th, 2009 01:55 PM
BLL and DAL kss BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 13 November 24th, 2008 03:59 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
New excerpt article: Using Generic Methods jminatel C# 2005 0 May 5th, 2006 04:23 PM
Excerpt article: Using Generic Methods jminatel .NET Framework 2.0 0 May 5th, 2006 04:19 PM





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