The Person Class

    The Person Class


    The person class is a simplistic class used for illustration. It implements the Personable interface and is abstract which means you can't instantiate it... you knew that.

    Person Class

    The name parts are set through the setNamePart(NamePart, String) method which validates the name part before setting it.

    The Id is set through the setId(String) method which the abstract Person class does not implement. This is to provide better control to the descendants over the Id's structure. The only requirement by the Person class is that this property is a string.

    public abstact class Person implements Personable{    // The Members    private int id;    private String salutation;    private String first;    private String last;    private String middle;    private String suffix;    // Constructor 1 - set id and basic name parts    public Person(int id, String fname, String mname, String lname){       this.setId(id);       this.setNamePart(NamePart.FIRST, fname);       this.setNamePart(NamePart.LAST, lname);       this.setNamePart(NamePart.MIDDLE, mname);    }    // Constructor 2 - set id and all name parts    public Person(int id, String sal, String fname, String mname, String lname, String suffix){       this.setId(id);       this.setNamePart(NamePart.SALUTATION, sal);       this.setNamePart(NamePart.FIRST, fname);       this.setNamePart(NamePart.LAST, lname);       this.setNamePart(NamePart.MIDDLE, mname);       this.setNamePart(NamePart.SUFFIX, suffix);    } }    // Method to set the Id goes here (coded in the descendants)...    // Method to set the name part goes here... The Basic Class Structure...





























    CREATED 2020-10-08 07:18:24.0

    010-00-03-59

    UPDATED 2020-10-08 07:18:41.0

    The Personable Interface


    Personable enforces the setId(String) method which is not implemented in the Person class. Descendant classes must implement this method.

    This allows the descendants to instill their own structure of the id as long as it fits the basic requirement. It must be a string.

    CREATED 2020-10-09 03:42:27.0

    010-00-03-5B

    UPDATED 2020-10-09 03:42:41.0

    The NamePart Data Type...


    The NamePart enumerated data type is used to enforce the name parts. As with most enums if prevents fat finger mistakes and is easier to compare.

    public enum NamePart{    SALUTATION("Salutation", 10, "The Name Salutation"),    FIRST("FirstName", 21, "The First Name"),    MIDDLE("MiddleName", 22, "The Middle Name"),    LAST("LastName", 23, "The Last Name"),    SUFFIX("Suffix", 30, "The Name Suffix");    private String title;    private int id;    private String description;    Person(String t, int i, String desc){       this.setId(id);       this.title = t;       this.id = i;       this.description = desc;    }    ... } The NamePart enumerated data type...


















    CREATED 2020-10-10 10:26:42.0

    010-00-03-5C

    UPDATED 2020-10-10 10:26:59.0

    Setting the Members...


    As stated the individual name parts are set using the setNamePart(NamePart, String) method.

    This method validates the parameter before setting it using the checkName(String) method. All name parts must contain letters in proper case. Numbers, spaces and special characters are not permitted.

    private boolean checkName(String s){    if(isValidString(s)){       try{          // convert the string to a character array...          char[] parts=s.toCharArray();          // loop through the array...          for(char c : parts)}             // if a letter is not a character, return false             if(Character.isLetter(c))}             }else{                return false;             }          }          // still here, the name is legit, return true.          return true;       }catch(NullPointerException npe){          return false;       }    }else{       return false;    } } The checkName method...




















    There are also convenience methods to set the name parts using set<name part>(String) structure. For example to set the last name use the setLastName(String) method.

    CREATED 2020-10-10 11:15:20.0

    010-00-03-5D

    UPDATED 2020-10-10 11:15:37.0

    The Heirarchy...


    Person Class

    The Person class is subclassed by Employee and Customer.

    Each of the subclasses brings personalized functionality to their perspective classes.

    For example the customer doesn't have a hire date while the employee doesn't have a shipping address.

    CREATED 2020-10-08 08:55:39.0

    010-00-03-5A

    UPDATED 2020-10-10 11:15:31.0

    This Site...


    This is my personal site specifically designed for me... my fiends and family. All are still welcome. Be nice... be curtious... and read my Terms of Service.

    CREATED 2021-04-02 13:09:16.0

    010-00-06-FF

    UPDATED 2021-04-10 07:15:56.0

    Links From Here

    L
    I
    N
    K
    S

    DBID: northrop.wam

    Page Server: Northrop

    Copyright 2012 - 2019 Leistware Data Systems

    Powered by T-Handle

        Hello anonymous