QA

IOTA^_^    

Sams Teach Yourself ASP.NET in 21 Days, Second Edition
By Chris Payne
Table of Contents
Day 15.  Using Business Objects


Q&A

Q1:

When should I consider moving common ASP.NET functionality into a business object?

A1:

This is a highly subjective question. Many developers would say that all non-UI functionality should be moved into business objects, regardless of the application. However, this depends on the size of your application. When it only consists of a few pages, you might not need to add the complexity of a business object. Once you can logically see the tier divisions in your application, it may be a good idea to consider using business objects.

Q2:

Can I create an object that expects parameters when instantiated?

A2:

Absolutely. VB.NET and C# provide methods called constructors that allow you to specify how an object can be instantiated. This method is called new in VB.NET. In C#, it's simply the name of the class. For example:

 'VB.NET Class MyObject    Public overloads Sub New()       'do something    End Sub    Public overloads Sub New(strString as string)       'do something       ...    end sub End Class //C# class MyObject {    public MyObject() {       'do something    }    public MyObject(string strString) {       //do something       ...    } } 

This class has two constructors a default one that doesn't take any parameters, and one that takes a single string parameter. Inside the second constructor, you can perform any operation you want that uses that string. You could use the following line from an ASP.NET page:

 dim objMyObject as new MyObject("hello!") 

There are just a few things you need to know. Also be aware that you can only instantiate objects with the constructors you build. If you don't provide a constructor that doesn't take any parameters, you cannot do the following:

 dim objMyObject as new MyObject 

If you don't provide any constructors at all, VB.NET and C# automatically create one for you that doesn't take any parameters. Also, if you provide multiple constructors, be sure to use the overloads keyword in VB.NET to avoid errors that arise from having two methods with the same name.

For more information, see the VB.NET and C# documentation included with the .NET Framework SDK.

Q3:

Is there any way to make managed .NET objects backward compatible with COM objects?

A3:

You bet. The Assembly Registry tool (regasm.exe) will take the metadata from your .NET assemblies, export what is known as a type-library file, and register it, just like a COM object. You can then use your .NET objects just like older COM objects.

If you update the .NET object, you'll have to rerun regasm.exe for COM to notice the changes. This may require restarting IIS, depending on your situation.

Q4:

How do I find out the filenames for COM objects? Or how do I find out the progId values?

A4:

This can be rather difficult sometimes. The easiest way is to use a programming environment, such as Visual Studio.NET. These applications allow you to look through class libraries of available COM objects and find the filenames.

Or, you can go into the Windows Registry and search for the object you need. You can often find both the prodId and the filenames there.

Finally, you can use an application called the OLE/COM Object Viewer, usually bundled with MS Visual Studio, to determine the necessary strings.

For .NET objects, the methods are much easier. Usually, all of the .NET Framework classes are in files named after the namespaces. For example, the System namespace objects are in System.dll, and the DataGrid object is in System.Data.dll.


    IOTA^_^    
    Top


    Sams Teach Yourself ASP. NET in 21 Days
    Sams Teach Yourself ASP.NET in 21 Days (2nd Edition)
    ISBN: 0672324458
    EAN: 2147483647
    Year: 2003
    Pages: 307
    Authors: Chris Payne

    Similar book on Amazon

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net