People in C#
The Person class is one of the most basic classes in the system and probably one of the most useful. The Person class represents a person in real time that can have as many contact details as he wants to. The current data stored in the Person class are:
Name
Surname
Title
Gender
Unlimited number of Addresses.
Unlimited number of Emails
Unlimited number of TelephoneNumbers
The design of the object stored all the contact data using a ContactData object which is an object that keeps track of the addresses, emails and telephone numbers of the person. Some people might wonder why have I designed the class in such a way. The main reason to use a CotactData object has been to allow the library to be modify in the near feature to allow an object to be able to holds more than one ContactData. Such an architecture would allows a Person to have different groups of contact data, for example a group for the contact data of the office, the contact data used at home and the contact data in a different country.
Creating People
People can be easily created using the Macaco.Contacts namespace. This code shows how to create a Person
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Macaco.Contacts; public class Program{ public static main(){ Person newPerson = new Person(Person.TitleEnum.MS, "Beatriz", "Aponte", Person.GenderEnum.FEMALE, Person.PrintModeEnum.NAME_SURNAME); } }
Managing the contact data
Once the object has been created we can programmatically add and remove contact data form the person. This is as simple as doing:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Macaco.Contacts; public class Program{ public static main(){ Person newPerson = new Person(Person.TitleEnum.MS, "Beatriz", "Aponte", Person.GenderEnum.FEMALE, Person.PrintModeEnum.NAME_SURNAME); // adding data EmailAddress email = new EmailAddress( "[email protected]"); Address address = new Address( Country.GetCountryByName("Germany"), new State("BER", "Berlin"), "Berlin", "street", "2332")); Telephonenumber number = new TelephoneNumber( "0034", "91", "3199670"); // adding the data newPerson.ContactDetails.Add(email); newPerson.ContactDetails.Add(address); newPerson.ContactDetails.Add(number); } }
Default data
In the Person class there are three special contact details that are set up as the default contact data. The default contact data represents the data that we want to use with the contact data when we want to contact him when we do not specify which contact data to use.
The default behavior of the Person class is to set up the first value of each of the contact details as the default data, but that can be easily set using the properties:
DefaultEmailAddress
DefaultAddress
DefaultTelephoneNumber
In the above code we add an other email address and set it up as the default email address to be used when contacting the person.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Macaco.Contacts; public class Program{ public static main(){ Person newPerson = new Person(Person.TitleEnum.MS, "Beatriz", "Aponte", Person.GenderEnum.FEMALE. Person.PrintModeEnum.NAME_SURNAME); // adding data EmailAddress email = new EmailAddress( "[email protected]"); Address address = new Address( Country.GetCountryByName("Germany"), new State("BER", "Berlin"), "Berlin", "street", "2332")); Telephonenumber number = new TelephoneNumber( "0034", "91", "3199670"); // adding the data newPerson.ContactDetails.Add(email); newPerson.ContactDetails.Add(address); newPerson.ContactDetails.Add(number); // default email address EmailAddress default = new EmailAddress( "[email protected]"); // we have to add first, otherwhise we will get an exception newPerson.ContactDetails.Add(default); // set as default newPerson.ContactDetails.DefaultEmailAddress(default); } }
Summary
The Person clas gives an useful object that can be used to represent human being contacts in a system. This class can be used without using the Macaco.Contacts.Data namespace, but when using it with it we will be able to tore contacts in a data back end of out choice, letting hte developer to focus on more interesting functionalities for hi application.













