Agility eLetter June, 2003


In this issue...

In this issue, we have a detailed article on "Servlets, JSP, Struts and MVC."

Abstract:Servlets and JSPs bring significant advantage to web development, yet come with significant limitations. In this article, we discuss what's fundamentally wrong with servlets and JSPs, discuss the Model 1 and the MVC based Model 2 architecture, and introduce the benefits of using a framework like Struts. The complete article can be found at the Agile Developer download page http://www.agiledeveloper.com/download.aspx.

Message from us

If you would like any question to be addressed or topic to be discussed, please send us an email at agility@agiledeveloper.com. At the end of the year, one person will be randomly selected from the list of respondents for a special prize. We would like to hear from you.

Please send suggestions, corrections and comments to agility@agiledeveloper.com.

Quiz corner

Let’s say a C# class A has the following:

 

public class A

{

     private static int[] vals;
    

}

 

I want to initialize the elements of the vals array to some arbitrary values. (Say that I may want to read the values from a configuration file or may be fetch the data from a database, etc.) How would I go about doing that, so that the vals will be ready and available before any method of A would need to use it?

Send your response to agility@agiledeveloper.com, and you may become the winner of this year's Agility special prize.


Quiz from the past issue

Assume that I have a class Base whose constructor looks like this:

            public Base()

            {

                  foo();

            }

where foo is a method that may be overridden by a derived class if desired. The body of the foo method contains no code (empty). Also, I have a class named Derived which inherits from the above mentioned class. It has one field

 

            private SomeClass obj = new SomeClass();

where SomeClass is a class with a method named “method.” Derived overrides the base class method foo with the following implementation:

           obj.method();

 

Now, what is the effect of creating an object of Derived using

           new Derived();

Answer!

Thanks to those who wrote to us with a response to this quiz. Your names have been entered for the year end drawing! Sadly, no one got the answer right this time, even though Vijay came close.

The answer is - it depends on which language you are using!

If you are using Java, the result is an NullPointerException begin thrown. However, if you are using C#, the result is proper execution and invocation of the method of SomeClass. This is  because (strangely) C# initializes the members of a class in the reverse order of derivation, i.e., members of Derived are initialized before members of Base. Then, the constructor is called in the order of derivation, i.e., the constructor of Base is called before the constructor of Derived is called.

Subscription Information

To subscribe or unsubscribe to the free issues of Agility eLetter, please visit http://www.agiledeveloper.com/eLetter.aspx.

Thus spake...

A pessimist sees the difficulty in every opportunity; an optimist sees the opportunity in every difficulty. – Winston Churchill.