concept base class in category .net

appears as: base class, base classes, base classes, The base class
ASP.NET AJAX in Action

This is an excerpt from Manning's book ASP.NET AJAX in Action.

  • Lets you specify a base class and takes care of automatically resolving the inheritance relationship
  • In JavaScript, you can override a method by assigning a new function to the same property: You replace the previous function with the new one. This raises an interesting question: If you’re deriving from a base class, how can you call the implementation of the base class if you’re replacing it? The answer is that you should store a reference to the base method before replacing it in the child class. The good news is that this is done automatically when you implement inheritance using the Microsoft Ajax Library. Base methods can be invoked through a method named callBaseMethod. Listing 3.10 shows how you can invoke the Pet implementation of the speak method from the child Cat class.

    Listing 3.10. Calling the implementation of a method defined in the base class
    Samples.Cat.prototype = { speak : function() { Samples.Cat.callBaseMethod(this, 'speak'); } }

    The first argument accepted by callBaseMethod is always the current instance, pointed to by this. The second argument is a string with the name of the method to invoke on the base class. In this case, because the base implementation of the speak method was defined in listing 3.4 to throw a client exception, the overridden method will behave in the same manner as the base method and throw the same client exception. If the base method accepts parameters, you encapsulate them into an array and pass it as the third argument to callBaseMethod, as shown in figure 3.5.

    3.4.2. Passing arguments to the base class

    To pass arguments to the constructor of the base class, you have to pass them to the initializeBase method. Let’s rewrite the constructor of the Pet class to accept the values of the _name and _age members as arguments:

    Listing 3.9. How to pass arguments to the constructor of the base class