|
-
Dec 3rd, 2003, 01:36 AM
#1
Thread Starter
Frenzied Member
Singleton and factory?
Hi!
I was wondering, if I develop an ASP.NET application (or vb.net C/S), can anyone point me to a page, or give a quick example how I can benefit from using the factory and singleton patterns? I already use the MVC pattern for the overall structure. Are they applicable here in this scenario?
Its a standard database-driven application using 3-tire layering
kind regards
Henrik
-
Dec 3rd, 2003, 07:33 AM
#2
Fanatic Member
Not sure what 3-tire layering is , but the desing patterns that you mention are separate from your 3 tier MVC architecture. They wouldn't have an effect, because they are implemented in your business tier. Singleton would let you only create one instance of a particular class (which is usefull if you want all objects to use the one instance) and Factory abstracts the creation of objects by taking in a request and then determining what object should be created and sending it back. Both are very useful, you just need to decide if they will benefit your scenario.
-
Dec 3rd, 2003, 08:58 AM
#3
Thread Starter
Frenzied Member
but when is it useful to use the factory pattern? I think I use it when I enable data access to my pages.. I have a static class wich accepts a database name as parameter and return a connection object (sql)
I guess that is due to the factory pattern??
/Henrik
-
Dec 3rd, 2003, 09:17 AM
#4
Fanatic Member
Yes, that is a type of factory pattern. All your code doesn't have to know which connection object it should use, it just passes the parameter to your static class and gets the correct one back to use. You could also implement it as a class that all your page requests call, and then the page is returned through that class.
-
Dec 4th, 2003, 01:23 AM
#5
Thread Starter
Frenzied Member
So I see...
Another question on a slightly different matter. As I strife towards designing good programs, I often try to use polymorphism as often as I can. And one way to implement polymorphism is to make use of interfaces.
For example, I have a method within a class that is called PrintResults (asp.net) which takes a datareader INTERFACE as in parameter, and then spit out the results with Response.writes...
I also have a method which is called GetResults, which fetch information from a database (with factory patter for dbconn) and store it in a datareader. I then return the INTERFACE of this datareader.
Is this the correct way to implement polymorphism? When should I work with interfaces instead of ordinary objects?
kind regards
Henrik
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|