Singleton vs. Abstract Factory Pattern

By Michael Flanakin @ 10:52 PM :: 114 Views :: 0 Comments :: .NET, Patterns & Practices :: Digg it!

Question

We have an application which calls an abstract factory, gets the appropriate class to work with. Below is a sample of the code

This is an example of the code which calls the abstract factory:

ImageSigner signer = ImageSigner.Create(
    originalFilename,
    HttpContext.Current.User.Identity.Name,
    strDeviceID,
    platform
    );
signer.Sign();

In ImageSigner.Create I have something like this:

case ".bin":
    imageSigner = new BinFileSigner();
    break;
case ".nb0":
    imageSigner = new Nb0FileSigner();
    break;
case ".dio":
    imageSigner = new DioFileSigner(platform);
    break;

We have found that the “signer.Sign()” call above consumes a lot of memory and processing power. I have been suggested to use a Singleton pattern over the Abstract Factory so that the requests are queued and worked upon in a synchronous fashion so that the system is able to handle multiple requests (although with slower response time) without crashing.

My problem is that I am not able to find an example of a Singleton Pattern implemented over an Abstract Factory Pattern. I have been trying to look up online but only able to find samples which implement each of these patterns separately.

Do you know of some place where I can find some related information, or if you have some piece of code which does that can you share that with me..

Answer

First off, I’d have to suggest you dig into the ImageSigner.Sign() method to find out what’s causing the problem. Are you expecting this to be a long-running process? If so, consider making it asynchronous; although, I’m not sure speed seems to be your concern.

As for replacing the abstract factory, I don’t think that’s the right approach. If queuing is what you want, either use a static method on the ImageSigner class or create a helper class. A helper class can implement singleton or not, depending on how you want it to exist in memory, which could potentially have performance implications. The static method should suffice, I would imagine. After you create the object instance with the factory, just call ImageSigner.Sign(signer). In-turn, this method would add the object to a collection and asynchronously kick-off the signing process one-by-one. Of course, you may want to differentiate the names in the two somewhat related methods so they’re not confused. I’d also suggest taking visibility into consideration.


Comment Spam

By Michael Flanakin @ 1:00 PM :: 111 Views :: 0 Comments :: .NET :: Digg it!

Question

Actually I have one website running on my webserver. This site contains one textbox on an aspx page. I have a server side validation for this textbox.

But I get following exception:

Exception Type:        System.Web.HttpException
Exception Message:     Unable to validate data.
Exception Source:      System.Web
Exception Target Site: GetDecodedData

Actually some spammer try to put following data into textbox thats why the errors are comming:

Hi everybody! Wanna see my cool pages? Please visit my homepage too:
<a href= http://celexa.ne1.net/index.html >celexa drug</a> celexa drug <a href= http://celexa.ne1.net/celexa-side-effects.html >celexa withdrawal</a> celexa withdrawal <a href= http://celexa.ne1.net/celexa-weight-gain.html >celexa side effects</a> celexa side effects <a href= http://celexa.ne1.net/celexa-withdrawal.html >celexa side effects</a> celexa side effects <a href= http://celexa.ne1.net/celexa-anxiety.html >celexa</a> celexa <a href= http://celexa.ne1.net/buy-celexa.html >buy celexa</a> buy celexa
                                 
Is there any possible way to stop that type of spamming.

Answer

I'm with Jeff, CAPTCHA is probably the best option in the way of defending against comment spam. Stripping HTML might be nice, but it won't stop the spam. One other option I might pose to you is to take a look at the ASP.NET AJAX Toolkit's NoBot control. This attempts to identify bots without requiring user interaction. I haven't used it, but it might be worth a look.

http://ajax.asp.net/ajaxtoolkit/NoBot/NoBot.aspx

Web Content Management

By Michael Flanakin @ 4:18 PM :: 79 Views :: 0 Comments :: .NET :: Digg it!

Question

I have a need to allow a few individuals in different departments of our company to edit content on our website.  However, I want to enforce a common theme / style over each area.  One paticular department has one main page with links to about 50-60 other static pages, each with dozens of links.  One approach ive thought of is to replace each of the static link pages with an xml file that contains the links for that section, then have only one aspx page that lets them choose the area they want, which then loads the links from the related xml file.

Answer

Personally, I'd consider using a tool like DotNetNuke, which already has all of this built in. This way, you can give them as little or as much control as you want and all you have to worry about is getting it setup. I admit that DNN can sometimes be a pain to get up and running the first time, but this is usually just because of not doing things correctly. Once you get experience with the product, it's almost second nature. While DNN doesn't have everything and there's probably a lot that could be done better, I try to look at it as a great starting point. If you want something changed, you can do it yourself.

Managing JavaScript

By Michael Flanakin @ 9:10 PM :: 82 Views :: 0 Comments :: Patterns & Practices :: Digg it!

Question

I was wondering if when developing custom controls in asp.net that need client script if it is better to emit the script inline with the code or to use a script file that the page can refer to. Any ideas would be much appreciated.

Answer

Personally, I see three options. In preferencial order, they are (a) a separate JS file; (b) a cache-enabled ASPX file; and, (c) inline scripting. Use a JS file in any case where your script is static. The reason behind this is that modern web browsers will cache these files and ensure your app performs as best as possible -- remember that JavaScript is parsed when executed, so every little bit helps. If you require dynamic content, try putting the script in a separate ASPX page that utilizes cache headers to maximize the cacheability. In the event that you have code that is dependant upon server controls, use inline scripting. Even if you do go this route, tho, I'd suggest calling functions that are specified in cache-controlled locations to minimize page size and maximize performance.

On a side note, if you have no more than 5-10 lines of code, I wouldn't worry about it. Just stick it on the page since that's the simplest method. The real reasons to separate script into its own file is for performance and/or maintainability... well, and all the other *ilities, as well :-)

Graphing in .NET 2.0

By Michael Flanakin @ 4:14 PM :: 78 Views :: 0 Comments :: .NET :: Digg it!

Question

i want to generate graphs in asp.net 2.0 using given value. how it possible have u any idea...

Answer

There are quite a few third party controls that'll do this for you, but I'd suggest you take a serious look at SQL Reporting Services, if you're using SQL Server. I've had to look at this several times and Reporting Services gave me all the features I needed to get graphs and charts created and published in a very short amount of time. Reporting Services is very easy to work with, but you should find a few tutorials online, if you're interested.

Answer

Just to follow up on this, there's a ReportViewer control that comes with .NET 2.0. I don't know if the Express editions of Visual Studio support design-time features, but it's worth a look-see; especially, if you're only looking for charting capabilities.

Microsoft Developer Certifications

By Michael Flanakin @ 6:49 PM :: 82 Views :: 0 Comments :: .NET :: Digg it!

Question

I am looking at routes towards getting the MCPD certification and there appears to be a couple:

The original thought was to go via the MCTS(web) and then the MCPD(web) as this really gave us what we needed...however, I've been recommended by someone to do the MCAD and then upgrade to the MCPD instead of doing the MCTS as this will mean we would get more out of the qualification (ie, we would learn the fundamentals of asp.net in the mcad but not neccessarily in the mcts, and you get Web, Application and Distributed Applications instead of just Web if you went via the MCTS route)

Does anyone else have an opinion on this?  I'm a bit confused about which route to take...

(if it helps - what we're looking to get out of the qualification at the end is, well, a certificate, but also to learn asp.net better than the basic knowledge we've gathered just by watching videos and creating small websites and simple applications, ie, the knowledge is probably the most important part)

Answer

MCAD will help with the Windows and Web MCPDs, but not the Enterprise MCPD. The Enterprise MCPD is basically the top level, which requires Windows and Web MCPDs. If you get MCSD, then you can skip the Windows and Web MCPDs and go straight for the Enterprise MCPD.

Here's how it works...

Start with nothing, take 3 tests, get Windows or Web MCPD
    ...or, take 5 tests, get both Windows and Web MCPDs
    ...or, take 7 tests, get Enterprise MCPD
Start with MCAD, take 1 test, get Windows or Web MCPD
    ...or, take 2 tests, get both Windows and Web MCPDs
    ...or, take 4 tests, get Enterprise MCPD
Start with MCSD, take 2 tests, get Enterprise MCPD

Question

Marvellous! Thanks for that, definitely clears up the possible routes.

Which way through would I get the most out of in terms of needing training really on the foundations of asp.net?  I'm assuming the 3 tests from nothing would be via the mcts and the 5 tests via the mcad (maybe wrong). 

We can ignore the enterprise stuff for the mo.

Thanks for your input!

Answer

As far as what route would give you the best experience from a tech training point of view, I can't really say. I look at it this way: If you have a strong hold on .NET 1.x, then go for MCAD. If you know Windows and web along with another product (i.e. SQL Server, BizTalk, MSF), then go for MCSD. If you don't have a strong background in .NET 1.x, I'd simply stick with the .NET 2.0 route.

Based on what's required for MCA/SD, let me cover that in my chart, as well...

Start with nothing, take 3 tests, get Windows or Web MCPD
    ...or, take 5 tests, get both Windows and Web MCPDs
    ...or, take 7 tests, get Enterprise MCPD

Start with MCAD (3 tests), take 1 test, get Windows or Web MCPD
    ...or, take 2 tests, get both Windows and Web MCPDs
    ...or, take 4 tests, get Enterprise MCPD

Start with MCSD (5 tests), take 2 tests, get Enterprise MCPD

What does this mean? Well, starting from nothing, here are your routes...

Start with nothing; take 3, 5, or 7 tests; get each MCPD (see above)
   ...or; take 4, 5, or 9 tests; get MCAD and each MCPD (see above)
   ...or; take 7 tests; get MCSD and Enterprise MCPD 

As you can see, if you don't have anything and you go the MCAD route, you're actually signing up for more work. If you get the full MCSD first, then you'll be doing the same amount of work with one caveat: Your two upgrade exams will be all-encompasing, whereas each individual exam will be more specialized. If you've ever prepared for an exam, you can see the problem with this.

Hope this helps! I think I might pull together a chart that shows it a little more visually. I'll keep you updated, if I do.





Archives Archives

Categories Categories

Related Links Related Links

 Sightings

ASP.net

CodeProject Gold Level Member