《模式——工程化实现及扩展》(设计模式C# 版)《原型模式 Prototype》——“自我检验"

转自:《模式——工程化实现及扩展》(设计模式C# 版)

http://www.cnblogs.com/callwangxiang/

 


 自我检验

假设由你完成一个企业申报数据序列化的程序,企业信息实体需要按照“计算机信息系统集成资质”1级的要求将满足申报条件的信息序列化。请结合本章介绍的自定义深层复制方式,实现原型对象,并通过单元测试验证。

为了便于示例,对“计算机信息系统集成资质”1级的要求节选如下:

1、 近三年内完成至少两项3000万元以上系统集成项

2、 具有计算机信息系统集成项目经理人数不少于25名,其中高级项目经理人数不少于8

 

示例并不对企业整体是否满足申报要求进行审核,仅对满足申报要求的类成员进行筛选。示例涉及的数据结构如下,请改造Enterprise类为原型模式类型:

 


[Serializable]
class Project
{
    
/// <summary>
    
/// 结项年份
    
/// </summary>
    public int EndYear { getset; }

    
/// <summary>
    
/// 项目资金规模(万元)
    
/// </summary>
    public double Scale { getset; }
}

[Flags]
enum QualificationOptions
{
    Assisstant,      
//  助理级
    Professional,    //  专家级
    Senior,          //  高级、资深级
    Principal        //  主任、主管级
}

[Serializable]
class Certification : IComparable<Certification>
{
    
public string Name { getset; }
    
public QualificationOptions Qualification { getset; }

    
public int CompareTo(Certification other)
    {
        
if(other == nullthrow new ArgumentNullException("other");
        
if(!string.Equals(other.Name, Name)) throw new NotSupportedException();
        
if(Qualification == other.Qualification) return 0;
        
return Qualification > other.Qualification ? 1 : -1;
    }
}

[Serializable]
class Employee
{
    
public string Name { getset; }
    
public Certification[] Certificates { getset; }
}

[Serializable]
class Enterprise : ISerializable
{
    public string Name { getset; }
    
public Project[] Projects { getset; }
    
public Employee[] Staff { getset; }
}

 

posted @ 2011-06-02 15:28  蜡笔小王  阅读(1592)  评论(0编辑  收藏  举报