using System; using System.Collections.Generic; using System.Text; namespace perfectbeanprop { public class Person { public Person( String firstName, String lastName) { this.setFirstName(firstName); this.setLastName(lastName); this.setCountryOfBirth(DEFAULT_COUNTRY_OF_BIRTH); } public Person( String firstName, String middleName, String lastName, String countryOfBirth) { this.setFirstName(firstName); this.setMiddleName(middleName); this.setLastName(lastName); this.setCountryOfBirth(countryOfBirth); } // // FirstName // // Mandatory property. // private String m_firstName = null; public String getFirstName() { if (m_firstName == null) { throw new Exception("firstName not set"); } return m_firstName; } public void setFirstName(String firstName) { if (firstName == null) { throw new ArgumentNullException("firstName cannot be null"); } if("".Equals(firstName)) { throw new ArgumentException("firstName cannot be blank"); } m_firstName = firstName; } // // MiddleName // // Optional property. // private String m_middleName = null; public String getMiddleName() { return m_middleName; } public void setMiddleName(String middleName) { m_middleName = middleName; } public Boolean hasMiddleName() { return m_middleName != null; } public void clearMiddleName() { m_middleName = null; } // // LastName // // Mandatory property. // private String m_lastName = null; public String getLastName() { if (m_lastName == null) { throw new Exception("lastName not set"); } return m_lastName; } public void setLastName(String lastName) { if (lastName == null) { throw new ArgumentNullException("lastName cannot be null"); } if("".Equals(lastName)) { throw new ArgumentException("lastName cannot be blank"); } m_lastName = lastName; } // // CountryOfBirth // // Mandatory property with default value. // private static readonly String DEFAULT_COUNTRY_OF_BIRTH = "Thailand"; private String m_countryOfBirth = null; public String getCountryOfBirth() { if (m_countryOfBirth == null) { throw new Exception("countryOfBirth not set"); } return m_countryOfBirth; } public void setCountryOfBirth(String countryOfBirth) { if (countryOfBirth == null) { throw new ArgumentNullException("countryOfBirth cannot be null"); } if ("".Equals(countryOfBirth)) { throw new ArgumentException("countryOfBirth cannot be blank"); } m_countryOfBirth = countryOfBirth; } public Boolean hasCountryOfBirth() { return m_countryOfBirth != null; } public void clearCountryOfBirth() { m_countryOfBirth = null; } } }