Tuesday, June 1, 2010

Misc Object Oriented concepts

An enumeration allows you to name a series of items only once and then use them everywhere. Here is the code for an enumeration of days of the week

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ScanCard1
{
public enum DaysOfWeek
{
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
}
}

A structure allows you to create a complex type. Again it is a way of keeping you from having to rewrite the same information over and over. Here is a stucture for addresses.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ScanCard1
{
public struct Address
{
string address1;
string address2;
string city;
string state;
string zipcode;


}
}

An interface is sometimes referred to as a contract. An interface consists only of method signatures. any class that implements an interface MUST implement all its methods. Here is the interface:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ScanCard1
{
public interface iManage
{
void Add(object s);

void Edit(object s);

void Remove(object s);
}
}

Here is a clsss that implements the IManage interface

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ScanCard1
{
class ManageScan:iManage
{
#region iManage Members

void iManage.Add(object s)
{
throw new NotImplementedException();
}

void iManage.Edit(object s)
{
throw new NotImplementedException();
}

void iManage.Remove(object s)
{
throw new NotImplementedException();
}

#endregion
}
}

Finally, here is an Abstract Class. It is a sort of a combination of an interface and a structure. It cannot be instantiated in itself. Only its children can be instantiated. Here is an abstract class.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ScanCard1
{
public abstract class Class1
{
private int FirstName;

public int FirstName1
{
get { return FirstName; }
set { FirstName = value; }
}
private int LastName;

public int LastName1
{
get { return LastName; }
set { LastName = value; }
}

public virtual void GetPersonInfo()
{

}
}
}

I will do a program soon that uses all these elements to provide a working example

No comments:

Post a Comment