Tuesday, April 14, 2009

Creating the Model

Has I am converting the Powerbuilder Application to Visual Studio I start going through the steps I would normally take when creating a new application. The first thing I do is create the database, but because this is an existing application this step is already taken care of for me. Here is the problem, there are over 200 tables...this is going to be quit a lot of Business Objects I'll need to create for this. I would recommend, if you are using an existing database, checking to see if the table is being used, if it's not don't worry - right now - about creating its model.

Visual Studio 2008 make creating Business Objects much easier....

In VS 05 and earlier we needed to create models like this.

public class UserInfo
{
private string _firstName;
private string _lastName;
private string _fullName;
private DateTime _dateOfBirth;

public UserInfo()
{
}

public string Firstname
{
get { return _firstName; }
set { _firstName= value; }
}

public string Lastname
{
get { return _lastName; }
set { _lastName= value; }
}

public string Fullname
{
get { return _lastName + "," + _firstName; }
set { _fullName= value; }
}

public DateTime DateOfBirth
{
get { return _dateOfBirth; }
set { _dateOfBirth= value; }
}
}

This should like something you have created in the past.

Today in VS 08, Microsoft has simplified this

public class UserInfo
{
public string _firstName{ get; set; }
public string _lastName{ get; set; }
public string _fullName
{
get{ return _lastName + "," + _firstName; }
set;
}
public DateTime _dateOfBirth { get; set; }
public UserInfo() {}
}

That is it. You should notice that the return and value settings are now implied. You can still expand the getter or setter, like we did in _fullName. But you can't argue the fact that this model is much easier to read

No comments: