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

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.

主站蜘蛛池模板: 丹寨县| 万安县| 黄山市| 新化县| 肇州县| 莎车县| 塔河县| 休宁县| 车致| 长乐市| 新郑市| 秦安县| 东光县| 金沙县| 甘泉县| 驻马店市| 蒲城县| 苏尼特右旗| 弥渡县| 台江县| 玉田县| 垦利县| 青阳县| 邢台县| 孟村| 永兴县| 大城县| 惠水县| 吉首市| 古交市| 衡南县| 舟山市| 镇赉县| 贺兰县| 抚州市| 霍山县| 花莲县| 工布江达县| 宜都市| 昌邑市| 佛山市|