How to implement and extend Joshua's builder pattern in .net?

后端 未结 4 1643
粉色の甜心
粉色の甜心 2021-01-30 05:35
  • How can we implement the Builder pattern of Joshua\'s Effective Java in C#?

Below is the code I have tried, is there a better way to do this?



        
4条回答
  •  无人共我
    2021-01-30 06:30

    This blog entry might be of interest

    A neat variation on the pattern in C# is the use of an implicit cast operator to make the final call to Build() unnecessary:

    public class CustomerBuilder
    {
    
       ......     
    
       public static implicit operator Customer( CustomerBuilder builder ) 
       {  
          return builder.Build();
       } 
    }
    

提交回复
热议问题