官术网_书友最值得收藏!

How it works...

If a struct provides a method called new that returns Self, the user of the struct will not configure or depend upon the members of the struct, as they are considered to be in an internal hidden state.

In other words, if you see a struct that has a new function, always use it to create the structure.
This has the nice effect of enabling you to change as many members of the struct as you want without the user noticing anything, as they are not supposed to look at them anyway.

The other reason to use this pattern is to guide the user to the correct way of instantiating a struct. If one has nothing but a big list of members that have to be filled with values, one might feel a bit lost. If one, however, has a method with only a few self-documenting parameters, it feels way more inviting.

主站蜘蛛池模板: 佛冈县| 丹巴县| 永仁县| 宣城市| 衡阳县| 沽源县| 石家庄市| 山丹县| 兴业县| 翁源县| 澄城县| 临沭县| 平凉市| 郁南县| 石泉县| 承德市| 奈曼旗| 涡阳县| 广汉市| 秦安县| 肇州县| 景泰县| 三穗县| 金乡县| 昌黎县| 信丰县| 滕州市| 都江堰市| 抚远县| 勐海县| 辽阳市| 南京市| 鹰潭市| 蛟河市| 尚义县| 时尚| 迁安市| 和田县| 遵义市| 邹城市| 织金县|