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 March 25th, 2009, 11:29 AM
Authorized User
 
Join Date: Mar 2009
Posts: 75
Thanks: 16
Thanked 1 Time in 1 Post
Default Question about BizObject class.

Why all it's methods and properties were declared as static?
This is an abstract class, so why do wee need statics?
All objects that need to use those methods or/and properties inherit this class any way so they can access them.
 
Old March 25th, 2009, 02:44 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Quote:
Originally Posted by yevi View Post
Why all it's methods and properties were declared as static?
This is an abstract class, so why do wee need statics?
All objects that need to use those methods or/and properties inherit this class any way so they can access them.
They are declared as static because they are used by other static methods.

Take for example:

protectedstaticstring CurrentUserIP
This is used by the InsertComment method, which is itself static. If CurrentUserIP were not static, you wouldn't be able to use it in the InsertComment method.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

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

This insertcommand method in Comment class
( public class Comment : BaseArticle , where BaseArticle inherits BizObject class)

So if we change the definition of CurrentUserIP to public , there will be no problem to access it from all classess that inherit BizObject.

So insertCommand can use it as: this.CurrentUserIP.

update:
Well , I've noticed only now that InsertCommand is also static...

Is it a good practice to use so many statics methods and classes?


Last edited by yevi; March 25th, 2009 at 03:28 PM..
 
Old March 25th, 2009, 03:47 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Quote:
Originally Posted by yevi View Post
update:
Well , I've noticed only now that InsertCommand is also static...
Isn't that exactly what I pointed out in my first reply? Perhaps you missed that.

Using statics is a great idea if you do not want to have to create an instance of a class to use its methods.

Calling Comment.InsertComment(blah blah blah) is more straightforward than doing Comment comment = new Comment(), setting the properties, then calling comment.Insert(). However, there's nothing stopping you from doing it that way if you want.
__________________
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; March 25th, 2009 at 03:50 PM..
The Following User Says Thank You to Lee Dumond For This Useful Post:
yevi (March 25th, 2009)
 
Old March 25th, 2009, 04:11 PM
Authorized User
 
Join Date: Mar 2009
Posts: 75
Thanks: 16
Thanked 1 Time in 1 Post
Default

Thanks.
I got the point.
 
Old March 25th, 2009, 04:22 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

My pleasure, anytime.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

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

As I mentioned earlier, i want to remove all static declaration from all businesses classes.
But I don't want to change much the original design, doing so I've encountered some problems that I hope you will help me to solve.

First problem I've encountered changing Category class.
In this class there is a property with it's getter:

Code:
private List<Article> _allArticles = null;
        public List<Article> AllArticles
        {
            get
            {
                 
                if (_allArticles == null)
                    _allArticles = Article.GetArticles(this.ID, 0, MAXROWS);
                return _allArticles;
            }
        }
As you can see I cannot use Article.GetArticles(...)
What would be the best option in my case scenario?
Should I pass Article class' instance as parameter to Category instance?
(In this case i will pass and store whole Article class for just one method)

Maybe I should use delegates with events to point to GetArticles method in Article instance?

Maybe I should completely change the design to meet my needs (that i don't want to do) or maybe partial change involving just the part of retrieving Articles from category?
 
Old April 11th, 2009, 02:36 PM
Friend of Wrox
Points: 546, Level: 8
Points: 546, Level: 8 Points: 546, Level: 8 Points: 546, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2009
Posts: 105
Thanks: 3
Thanked 20 Times in 19 Posts
Default

Or, maybe you should use the statics to avoid the problem you've created for yourself by trying to eliminate them.

There is nothing wrong with using statics; and in some cases, like with the tbh design there are distinct advantages of using them; you don't have to have an instance of an object to call a method and you don't need to pass a reference around as a parameter.

Marco has provided us an elegant, extensible and scalable design; before you discard it, make sure you fully understand it.


Steve
The Following User Says Thank You to Steve S For This Useful Post:
yevi (April 11th, 2009)
 
Old April 11th, 2009, 03:35 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

I guess I'm with Steve on this. I don't get your aversion to static classes/methods. To me, it seems like you're trying to create a solution to a non-existent problem.

There are cases where you may get away with using pure instance methods, but there are others in which it just doesn't make sense. For example, it makes no sense to create a default instance of an article just to call the GetArticles() method on it.

If you really want to do that, you would probably want to consider looking into an entirely different design pattern, like Factory or Respository. TBH uses the Active Record pattern, which doesn't lend itself well to non-static usages.
__________________
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 11th, 2009)
 
Old April 11th, 2009, 03:58 PM
Authorized User
 
Join Date: Mar 2009
Posts: 75
Thanks: 16
Thanked 1 Time in 1 Post
Default

Quote:
Originally Posted by Lee Dumond View Post
For example, it makes no sense to create a default instance of an article just to call the GetArticles() method on it.
Yes, I totally agree with you on this.

And after meeting more problems like this I am coming to a conclusion that if i want to avoid using static I need to completely change the design.





Similar Threads
Thread Thread Starter Forum Replies Last Post
BizObject class - Intellisense? ViagraFalls BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 September 19th, 2007 02:24 PM
Thoughts on BizObject hpox BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 7 June 9th, 2007 07:47 AM
Why is Cache Property used in BizObject ? Scott663 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 March 8th, 2007 10:47 PM
Can you give me an example of BizObject content ? dwfresh BOOK: ASP.NET Website Programming Problem-Design-Solution 0 December 19th, 2003 04:10 AM
Purpose of BizObject in Core? SBurton BOOK: ASP.NET Website Programming Problem-Design-Solution 1 August 6th, 2003 07:36 PM





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