Using .Net, Paul will demonstrate how to generate an object driven interface. A rich source of support material is included with this article so you can start building interfaces today.
An Object Driven Interface with .Net - Part 2: Creating our Business Object (Page 2 of 4 )
In this part, we are going to use the base and attribute classes that we created in the previous part to create a business object that we can use to generate our interface. We will base the business object on a simple customer object with Customer information, Contact details and an Address.
First we will create a very simple business object called Customer, in customer we will have a number of properties that make up the customer object.
Imports Web.Wizards.Base Imports System.Web.UI Public Class Customer Inherits WizardBase Private lNumber As String Private lName As String Private lContact As String Private lPhone As String Private lAddress1 As String Private lAddress2 As String Private lCity As String Private lPostal As String Private lActive As Boolean Public Sub New() CreateList("Code1", "Code2", "Code3") End Sub ... End Class
The class inherits from WizardBase therefore the class will automatically contain all the methods and properties that exist in WizardBase, in Sub New, we call the method Createlist in the BaseClass to create a List that we will later use when we generate our interface, in order for us to expose our Variables so that we can get get data from our user we create properties.
<WizardAttributes("Name", GetType(WebControls.TextBox), _ Helptext:="The Customers Name", _ SectionName:="Details")> _ Public Property Name() As String Get Return lName End Get Set(ByVal Value As String) lName = Value End Set End Property
The property declaration declares a Public Read/Write Property Called Name that is used to access the Private field lName, in the code above we also use the Custom attribute class we created “WizardAttributes”, with the custom attribute we specify that the label should state that the field is called Name, that a System.Web.UI.Webcontrols.TextBox should be used to render the Property, that when the user selects the Property Help should display “The Customers Name”, and that the property should fall under a section called “Details” on the property grid.