Using system;
Using system. collections;
Public class DB
{
Private Static arraylist list = new arraylist ();
Public static void addemp (string name)
{
List. Add (new employee (name ));
}
Public static iemployee searcheemployee (string empname)
{
Iemployee emptemp = nullemployee. getinstance ();
Foreach (employee EMP in List)
{
If (EMP. Name = empname)
{
Emptemp = EMP;
}
}
Return emptemp;
}
}
Public interface iemployee
{
Void sayhello ();
}
// Combined with Singleton
Public class nullemployee: iemployee
{
Private Static nullemployee EMP;
Private nullemployee (){}
Public static nullemployee getinstance ()
{
If (EMP = NULL)
EMP = new nullemployee ();
Return EMP;
}
Public void sayhello ()
{
Console. writeline ("null employee! ");
}
}
Public class employee: iemployee
{
Public Employee (string N)
{
Name = N;
}
Private string name;
Public string name
{
Get
{
Return name;
}
}
Public void sayhello ()
{
Console. writeline ("Hello! "+ Name );
}
Public override string tostring ()
{
Return "the employee name is:" + name;
}
}
Public class myclass
{
Public static void main ()
{
DB. addemp ("Randy ");
DB. addemp ("Edward ");
DB. addemp ("Flying ");
Console. writeline (db. searcheemployee ("Edward"). tostring ());
Console. writeline (db. searcheemployee ("fei"). tostring ());
DB. searcheemployee ("fei"). sayhello ();
Console. Read ();
}
}