Interview Question: Static class vs. Singleton pattern.

Question : Where would you choose a Singleton over a Static class?

I always expect two words to answer this question

  1. State : Static objects are not well-suited for good state management (think scalability).
  2. Weight : Don’t want too many heavy static objects floating in memory (think performance).

That would basically answer this question, but to be more fair and give a good explanation, I found a good article here [Link].

Including script files in masterpages (ASP.NET)

One of the issues I have faced with including site-wide JS files while developing web-applications is the simple fact that I was developing in Windows XP and IIS 5. And IIS puts in each of my websites as virtual-directories. So , I always have trouble including references to js files from the master-pages.

One alternative was to have a virtual directory outside the project structure and point it to the js folder, and my references would work properly. But there are other nicer ways to do the same.

1. Include the script tag as a server side tag, and give the reference to the file with a “~”

 <script language="javascript" src="~/App_Common/Scripts/tablecloth.js" runat="server"></script>

2. Add some code to your masterpage’s load event that would register the file after resolving the client url.

 protected void Page_Load(object sender, EventArgs e) { this.Page.ClientScript.RegisterClientScriptInclude(this.GetType(), "tableCloth", this.ResolveClientUrl("~/App_Common/Scripts/tablecloth.js")); } 

The above two approaches completely avoid having to create a virtual directory of any kind, and work all the time … so long as the path is correct.

[HowTo] Generate a dummy table for binding to a tabular structure.

While designing grids and related styles, I always found the need to bind some dummy data to the grid to see how the grid looks. So, rather than making a database call to get a really organized table, I decided to get one of my own.

The following method generates and returns a data-table to be bound to any tabular structure.

 1: public DataTable GetDummyData(int columnCount, int rowCount, bool useNumeric, int rowLength, int minNumber, int maxNumber)
 2: {
 3: DataTable dt = new DataTable();
 4: dt.Columns.Add(new DataColumn(" ", typeof(string)));
 5:  
 6: for (int c = 0; c < columnCount; c++)
 7: {
 8: string columnName = RandomString(rowLength, false);
 9: if (useNumeric == true)
 10: {
 11: dt.Columns.Add(new DataColumn(columnName, typeof(Int32)));
 12: }
 13: else
 14: {
 15: dt.Columns.Add(new DataColumn(columnName, typeof(string)));
 16: }
 17: }
 18: for (int j = 1; j <= rowCount; j++)
 19: {
 20: DataRow dr = dt.NewRow();
 21: dr[0] = RandomString(4, false);
 22: for (int k = 1; k <= columnCount; k++)
 23: {
 24: if (useNumeric == true)
 25: {
 26: dr[k] = RandomNumber(minNumber, maxNumber);
 27: }
 28: else
 29: {
 30: dr[k] = RandomString(rowLength, true);
 31: }
 32: }
 33: dt.Rows.Add(dr);
 34: }

      
 35: return dt;
 36: }

Disclaimer : Don’t use it for production. This is just to test on your local machines.

Interview Question: Class vs. Structure

As a part of my job, I interview potential candidates for jobs, and one of the standard questions I ask is ‘What is the difference between a class and a structure?’, and I sometimes am surprised with the kind of answers I get.

So, I decided, I should get some of these proper QnA’s for interview questions, and post them as a series.

  Class Structure
Type Reference Value
Performance Slower Faster
Storage Stack Heap (requires cleanup by GC)
Optimal size > 16 bytes < 16 bytes
Default protection level Private Public
Default Constructor Present Absent
Is Immutable No Yes

Misc references :

Healthcare delivery systems : Win apps or Web apps ?

A couple of weeks back, while I was contemplating on the health-care software delivery to a wide variety of users, I was inclined to realize that not one mode of delivery (either window-form based or web-form based) was suited to all with the same rate of acceptance. To help understand better, the users of the products/portals we develop include

  • Site administrators
  • Departmental administrators/supervisors
  • Physicians
  • Nurse(s), hospital/clinic staff
  • Brokers
  • Plan administrators
  • Company representatives (for small/large groups)
  • Underwriters
  • Medical underwriters
  • Account managers
  • Data-entry personnel
  • Support personnel
  • ….amongst others who are specific to the health insurance company we are working with.

With such a diverse population involved, the need for a web/win application depend on the frequency of usage of the system, and the amount of rich functionality that they require.

For example, a member (like you or me who are getting insurance from a company), will use the application for registering self and family, answering the medical questionnaire that describes the conditions me/my family might have, and a bunch of agreements along with the rates that the insurance company may want to offer. After this, a member’s interaction with the system is mostly for routine stuff like

  • Change the Primary Care Provider (PCP)
  • Change his address (so long as he/she is under the insurance coverage)
  • Change his contact details
  • Check out the claims submitted/approved/rejected (depending on how much the insurance company wants you to see)

A member is a perfect example of designing a member portal as a regular web-application on any browser.

However, when the staff members, underwriters, administrators, physicians want to use the same system, they are certain to have much more richer functionality than a web-application can seem to offer. Even with the latest advancements in web technology, the gap between rich client applications and rich Internet applications is still there. With such a requirement to meet to cater the needs of diverse sects in the intended population, there needs to be a hybrid approach or maybe a completely new revolutionary approach.

  • Sandboxing : This is the process of customizing the intended browser to make it more distraction-free, and clutter free. One approach to do this would be to strip the browser of everything and just keep the shell with a status bar that hopefully will be used as a regular one along with taking care of the settings for the shell. As I learnt today, Mozilla is coming up with something very similar in theory, and it has been christened as “Prism“. Though their concept is similar to mine, there remains an imminent issue of making it absolutely generic to support all kinds of clients, many an issue can come up thanks to the varied style of handling JS, CSS and the programming language of choice. However, in all honesty, I don’t think this would be an issue by the time they get it out to the public.
  • Always-connected : This approach would simply ask one to develop both windows applications and web-applications. Agreed that this is kind of a nightmare for small companies, but take the case of MS Money suite, and the newly released MS Healthvault. The idea of having a windows-app and a web-app at the same time is giving the end-user the choice of picking his/her comfort level, and catering his/her needs the same way irrespective of his/her choice. Unless there comes a time when the slowest internet-connection available has upload/download speeds at a minimum of 4Mbps/4Mbps respectively. Google gears also does a good job of this with Google Gears, but the technology has a long way to go to be mature and widely accepted. Trust in the storage provider is a major hurdle in this approach. How many of you would trust your health-information to any one other than yourself and your doctor. Heck, we don’t even have an option to opt out of “web-access” to the insurance company portals showing everything about you and your family’s health.
  • Web-desktop : There are a few approaches in this direction, however none are competent enough to provoke a shift in healthcare delivery.

In conclusion, depending on the size of the health-care company, one would choose either Sandboxing or Always-Connected approach. However, unless the web app technologies comes up with some ground-breaking advancements, this is what the future of healthcare delivery will be.