An Immutable Class

一个简单的Immutable Class:

class Contact
{
    
public Contact(String fullName, String phoneNumber)
    
{
        
this.fullName= fullName;
        
this.phoneNumber= phoneNumber;
    }


    
public Contact ChangeNumber(String newNumber)
    
{
        
//创建一个新实例
        return new Contact (this.fullName, newNumber);
    }


    
readonly String fullName;
    
public String FullName get return fullName; }}

    
readonly String phoneNumber;
    
public uint PhoneNumberget return phoneNumber; }}
}

posted on 2008-05-18 21:05  J.D Huang  阅读(313)  评论(0编辑  收藏  举报