Meter Mode (13) - Builder Mode (Builder)

Also called generator pattern.

 

Builder mode application scenarios:

When the internal data of a class is too complex, you may need to understand the internal structure of the class if you want to create it. At this time, the learning cost will increase and it will be very confusing. How to make it step by step when creating, and the code can be The readability is very good, don't make me dazzled, and everything I want can be well set in. This is the application scenario of the Builder pattern.

 

The most typical is the append usage of the two classes StringBuffer and StringBuilder.

StringBuffer sb = new StringBuffer("");
sb.append("a").append("b").append("c");

 The append() method returns itself a StringBuffer object each time.

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326118418&siteId=291194637