I've found my coding practices to be slipping lately - and noticed myself falling into some bad habits - usually due to lack of motivation on my part (probably caused but the inane nature of the tasks set for me) - So to give myself a kick up the behind I decided to write myself which should be a very simple, basic class. Here it is:
public class Customer
{
public string CUSTOMERNAME;
public List<Site> sites = new List<Site>();
public Customer()
{
}
public void AddSite(Site location)
{
sites.Add(location);
}
}
public class Site
{
public string SITENAME;
public Address SITEADDRESSDETAILS;
public string SITEPHONENUMBER;
public Site(string sitename, Address siteaddress, string tel)
{
SITENAME = sitename;
SITEADDRESSDETAILS = siteaddress;
SITEPHONENUMBER = tel;
}
}
public class Address
{
public List<string> address = new List<string>();
public Address() {
}
public void AddAddressDetail(string line)
{
address.Add(line);
}
}
Now everything seems to work but I just can't help feeling that things could be done better. I've tested it with the following code:
static void Main(string[] args)
{
Customer customer = new Customer();
customer.CUSTOMERNAME = "Max Hammer Ltd";
Address addy = new Address();
addy.AddAddressDetail("1 Edgerail Close");
addy.AddAddressDetail("Greenbushes");
addy.AddAddressDetail("Bluehill");
addy.AddAddressDetail("Surrey");
addy.AddAddressDetail("RH0 6LD");
Site surreyOffice = new Site("Surrey Office", addy, "01737 000000");
addy = new Address();
addy.AddAddressDetail("6 Electric Avenue");
addy.AddAddressDetail("Brixton");
addy.AddAddressDetail("London");
addy.AddAddressDetail("SW4 1BX");
Site brixtonOffice = new Site("Brixton Office", addy, "020 7101 3333");
customer.AddSite(surreyOffice);
customer.AddSite(brixtonOffice);
Console.WriteLine(customer.CUSTOMERNAME);
int numberOfSutes = customer.sites.Count;
for (int i = 0; i < numberOfSutes; i++)
{
Console.WriteLine(customer.sites[i].SITENAME);
foreach (string line in customer.sites[i].SITEADDRESSDETAILS.address)
{
Console.WriteLine(line);
}
Console.WriteLine(customer.sites[i].SITEPHONENUMBER);
}
Console.ReadKey();
}
I'm not happy with my Main
class and I'm not sure why - even though it does what I want. Any tips, pointers?