{"id":393089,"date":"2024-06-29T10:48:35","date_gmt":"2024-06-29T10:48:35","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=393089"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=393089","title":{"rendered":"<span>\u0428\u0430\u0431\u043b\u043e\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f: Composite<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f Composite (&#171;\u041a\u043e\u043c\u043f\u043e\u043d\u043e\u0432\u0449\u0438\u043a&#187;).<\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441 \u0442\u0435\u043e\u0440\u0438\u0438. <\/p>\n<p>\u041f\u0430\u0442\u0442\u0435\u0440\u043d Composite, \u0438\u0441\u0445\u043e\u0434\u044f \u0443\u0436\u0435 \u0441 \u0441\u0430\u043c\u043e\u0433\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043a\u043e\u043c\u043f\u043e\u043d\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043f\u043e \u0442\u0438\u043f\u0443 &#171;\u0434\u0435\u0440\u0435\u0432\u0430&#187;, \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u043e\u0442 \u0447\u0430\u0441\u0442\u043d\u043e\u0433\u043e \u043a \u0446\u0435\u043b\u043e\u043c\u0443, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c \u0435\u0434\u0438\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e \u0442\u0440\u0430\u043a\u0442\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u044d\u0442\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430. \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0438 \u043c\u0435\u043b\u043a\u0438\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0432 \u0431\u043e\u043b\u0435\u0435 \u043a\u0440\u0443\u043f\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043c\u043e\u0433\u0443\u0442 \u0441\u0442\u0430\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043e\u0439 \u0434\u043b\u044f \u0435\u0449\u0435 \u0431\u043e\u043b\u0435\u0435 \u043a\u0440\u0443\u043f\u043d\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/45e\/e64\/893\/45ee64893b1a7bcdc2d04956e4d6bb05.png\" width=\"308\" height=\"182\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/45e\/e64\/893\/45ee64893b1a7bcdc2d04956e4d6bb05.png\"\/><\/figure>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e57\/bf8\/bed\/e57bf8bed097283aa4bfabf771752c35.png\" width=\"651\" height=\"540\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e57\/bf8\/bed\/e57bf8bed097283aa4bfabf771752c35.png\"\/><\/figure>\n<p>\u0426\u0435\u043d\u0442\u0440\u0430\u043b\u044c\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0438\u043b\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 Component &#8212; \u043e\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0440\u044f\u0434 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438 \u043c\u043e\u0436\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0438\u043b\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0431\u0435\u0437 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0437\u0430\u0434\u0430\u0432\u0430\u043b\u0438 \u043a\u043b\u0430\u0441\u0441\u044b \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0438.<\/p>\n<p>\u041a\u043b\u0430\u0441\u0441 Composite &#8212; \u044d\u0442\u043e \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0434\u0435\u0440\u0435\u0432\u0430, \u043e\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u043e\u043c Component. \u041e\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0430\u0431\u043e\u0440 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 children: Componenntss[]. \u042d\u0442\u043e \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043a\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b-\u043b\u0438\u0441\u0442\u044c\u044f, \u0442\u0430\u043a \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u044b. \u041c\u0435\u0442\u043e\u0434\u044b \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u0435\u0440\u0435\u0430\u0434\u0440\u0435\u0441\u043e\u0432\u044b\u0432\u0430\u044e\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0441\u0432\u043e\u0438\u043c \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c, \u043d\u043e \u0438 \u043c\u043e\u0433\u0443\u0442 \u0447\u0442\u043e-\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u0432\u043e\u0451 \u043a \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0443.<\/p>\n<p>\u041a\u043b\u0430\u0441\u0441 Leaf &#8212; \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0434\u0435\u0440\u0435\u0432\u0430, \u043e\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u043e\u043c Componenta. \u0414\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u041e\u043d \u0442\u0430\u043a\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u044b, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043f\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0443 \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 Component. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043c\u043e\u0433\u0443\u0442 \u043d\u0435 \u0438\u043c\u0435\u0442\u044c \u0441\u043c\u044b\u0441\u043b\u0430 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u0435\u0442\u043e\u0434 add()), \u0432 \u0442\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>\u041a\u043b\u0430\u0441\u0441 Client \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043e\u0431\u0449\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0438\u043b\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 Composite \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u043c\u0443, \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043d\u0435 \u0432\u0430\u0436\u043d\u043e, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0434 \u043d\u0438\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f &#8212; \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438\u043b\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u043e\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0434\u0435\u0440\u0435\u0432\u0430.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043d\u0430\u00a0\u0434\u0432\u0443\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445. <\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0435\u0440\u0432\u044b\u0439.<\/strong> \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0440\u0430\u0441\u043f\u0435\u0447\u0430\u0442\u0430\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u043a\u043d\u0438\u0433\u0438. \u0412\u00a0\u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0438, \u043a\u0430\u043a\u00a0\u0440\u0430\u0437 \u0438 \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u0440\u0435\u0432\u043e\u0432\u0438\u0434\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430. \u041a\u0430\u0436\u0434\u0430\u044f \u0433\u043b\u0430\u0432\u0430 \u043a\u043d\u0438\u0433\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u00a0\u0441\u0435\u0431\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438\u00a0\u2014 \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u044b. \u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a\u00a0\u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043a\u043e\u0434\u0430.<\/p>\n<p>\u0412\u043d\u0430\u0447\u0430\u043b\u0435 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u00a0\u2014 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <code>ContentsComponent<\/code>. \u0412\u00a0\u043d\u0435\u043c \u043c\u044b \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432.<\/p>\n<p><code>public void add(ContentsComponent contentsComponent)<\/code>\u00a0\u2014 \u0432\u00a0\u0434\u0430\u043d\u043d\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u0432\u00a0\u043a\u043b\u0430\u0441\u0441\u0430\u0445 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430\u0445 \u043c\u044b \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043b\u043e\u0433\u0438\u043a\u0443 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f.<\/p>\n<p><code>public String getName()<\/code>\u00a0\u2014 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f\u00a0\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0433\u043b\u0430\u0432\u044b \u0438\u043b\u0438\u00a0\u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u0430.<\/p>\n<p>public Integer getPages()\u00a0\u2014 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f\u00a0\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u043e\u043c\u0435\u0440\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b.<\/p>\n<p><code>public void print()<\/code>\u00a0\u2014 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0432\u00a0\u043a\u043b\u0430\u0441\u0441\u0430\u0445 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432\u044b\u0432\u043e\u0434 \u043d\u0430\u00a0\u044d\u043a\u0440\u0430\u043d \u0433\u043b\u0430\u0432 \u0438 \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u043e\u0432.<\/p>\n<pre><code class=\"java\">public abstract class ContentsComponent {     public void add(ContentsComponent contentsComponent) { throw new UnsupportedOperationException(); } public String getName() { throw new UnsupportedOperationException(); } public Integer getPages() { throw new UnsupportedOperationException(); } public void print() { throw new UnsupportedOperationException(); } }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441 <code>Contents<\/code> \u0438 \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u0435\u0433\u043e \u043e\u0442 <code>ContentsComponent<\/code>. \u042d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0440\u043e\u043b\u044c \u043d\u0430\u0448\u0438\u0445 \u0433\u043b\u0430\u0432, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0443\u0436\u0435 \u0431\u043e\u043b\u0435\u0435 \u043c\u0435\u043b\u043a\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 (\u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u043e\u0432)\u00a0\u2014 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c <code>ArrayList &lt;\u0421ontentsComponents> contentsComponents.<\/code> \u0422\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u043b\u044f <code>name<\/code> \u0438 <code>pages<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u0437\u0430\u00a0\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0433\u043b\u0430\u0432\u044b \u0438 \u043d\u043e\u043c\u0435\u0440\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b.<\/p>\n<p>\u041f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043c\u0435\u0442\u043e\u0434 <code>public void print()<\/code>\u00a0\u2014 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0433\u043b\u0430\u0432\u044b \u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u0430\u00a0\u0442\u0430\u043a\u0436\u0435 \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0442\u044c \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 <code>contentsComponents<\/code> \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0443\u00a0\u043d\u0438\u0445 \u0441\u0432\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 <code>print()<\/code>.<\/p>\n<pre><code class=\"java\">public class Contents extends ContentsComponent { ArrayList&lt;ContentsComponent> contentsComponents = new ArrayList&lt;ContentsComponent>(); String name; Integer pages;  public Contents(String name, Integer pages) { this.name = name; this.pages = pages; }   public void add(ContentsComponent contentsComponent) { contentsComponents.add(contentsComponent); }  public String getName() { return name; }   public Integer getPages() { return pages; }   public void print() { System.out.print(\"\\n\" + getName()); for (int i = 0; i &lt; 70-getName().length(); i++) { System.out.print(\".\"); } System.out.println(getPages());  Iterator&lt;ContentsComponent> iterator = contentsComponents.iterator(); contentsComponents.stream() .takeWhile(x -> iterator.hasNext()) .map(n -> iterator.next()) .forEach(ContentsComponent::print);  } }<\/code><\/pre>\n<p>\u041f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043a\u043b\u0430\u0441\u0441\u00a0\u2014 <code>ContentsItem<\/code>. \u042d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u0442\u0430\u043a\u0436\u0435 \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u043e\u0442\u00a0<code>ContentsComponent<\/code> \u0438 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u0437\u0430\u00a0\u043d\u0430\u0448\u0438 \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u044b. \u0412\u00a0\u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0442\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u043f\u043e\u043b\u044f <code>name<\/code> \u0438 pages(\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u0430 \u0438 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b), \u043d\u043e\u00a0\u0443\u0436\u0435 \u043d\u0435\u0442\u0443 \u0441\u043f\u0438\u0441\u043a\u0430 \u043d\u043e\u0432\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0442\u0430\u043a \u043a\u0430\u043a\u00a0\u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0443\u00a0\u043d\u0430\u0441 \u043a\u0430\u043a\u00a0\u043b\u0438\u0441\u0442 \u043d\u0430\u00a0\u0434\u0435\u0440\u0435\u0432\u0435\u00a0\u2014 \u043d\u0435\u00a0\u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432\u00a0\u0441\u0435\u0431\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0434\u043b\u044f\u00a0\u043d\u0435\u0433\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043c\u0435\u0442\u043e\u0434 <code>public void print()<\/code>\u00a0\u2014 \u0433\u0434\u0435 \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u0430 \u0438 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b.<\/p>\n<pre><code class=\"java\">public class ContentsItem extends ContentsComponent { String name; Integer pages; public ContentsItem(String name, Integer pages) {  this.name = name; this.pages = pages; }    public String getName() { return name; }    public Integer getPages() { return pages; }     public void print() { System.out.print(\"  \" + getName()); for (int i = 0; i &lt; 68-getName().length(); i++) { System.out.print(\".\"); } System.out.println(getPages()); } } <\/code><\/pre>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043a\u043b\u0430\u0441\u0441 <code>Book<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c <code>ContentsComponent contents<\/code>, \u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0430\u0448\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>public void printContents()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u043d\u0430\u00a0\u043f\u0435\u0447\u0430\u0442\u044c.<\/p>\n<pre><code class=\"java\">public class Book { ContentsComponent contents;  public Book(ContentsComponent contents) { this.contents = contents; }   public void printContents() { contents.print(); } }<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0441\u044c \u043d\u0430\u0448 \u043a\u043e\u0434, \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441 <code>TestDrive<\/code>, \u0432\u00a0\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0434\u043b\u044f\u00a0\u043a\u043d\u0438\u0433\u0438.<\/p>\n<p>\u0412\u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0430\u043c\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435, \u043f\u043e\u0442\u043e\u043c \u0433\u043b\u0430\u0432\u044b \u0438 \u043f\u043e\u0442\u043e\u043c \u043a\u0430\u0436\u0434\u043e\u0439 \u0433\u043b\u0430\u0432\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u044b. <\/p>\n<pre><code class=\"java\">public class TestDrive {            public static void main(String[] args) {         ContentsComponent contents = new Contents(\"Contents \", 1);          ContentsComponent introduction = new Contents(\"1. Introduction \", 1);         ContentsComponent creatingAndDestroyingObject = new Contents(\"2. Creating and destroying object \", 5);         ContentsComponent methodsCommonToAllObject = new Contents(\"3. Methods common to all object \", 37);         ContentsComponent classesAndInterfaces = new Contents(\"4. Classes and interfaces \", 73);          contents.add(introduction);         contents.add(creatingAndDestroyingObject);         contents.add(methodsCommonToAllObject);         contents.add(classesAndInterfaces);          creatingAndDestroyingObject.add(new ContentsItem(                 \"2.1 Consider static factory methods instead of constructors \",                 5         ));         creatingAndDestroyingObject.add(new ContentsItem(                 \"2.2 Consider a builder when faced with many constructor parameters \",                 10         ));         creatingAndDestroyingObject.add(new ContentsItem(                 \"2.3 Enforce the singleton property with a private constructor \",                 17         ));          methodsCommonToAllObject.add(new ContentsItem(                 \"3.1 Obey the general contract when overriding equals \",                 37         ));          methodsCommonToAllObject.add(new ContentsItem(                 \"3.2 Always override hashCode when you override equals \",                 50         ));          classesAndInterfaces.add(new ContentsItem(                 \"4.1 Minimize the accessibility of classes and members \",                 73         ));         classesAndInterfaces.add(new ContentsItem(                 \"4.2 in public classes, use accessor methods, not public fields \",                 78         ));         classesAndInterfaces.add(new ContentsItem(                 \"4.3 Minimize mutability \",                 80         ));          System.out.println(\"\\\"Effective Java\\\" Joshua Bloch, 2018\");          Book book = new Book(contents);          book.printContents();      }      }<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0432\u044b\u0432\u043e\u0434 \u043d\u0430\u00a0\u044d\u043a\u0440\u0430\u043d.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/6d0\/c64\/46b\/6d0c6446be0a5cc97f725f3b998a16c1.png\" width=\"685\" height=\"560\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6d0\/c64\/46b\/6d0c6446be0a5cc97f725f3b998a16c1.png\"\/><\/figure>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u0432\u0442\u043e\u0440\u043e\u0439.<\/strong> \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0443\u00a0\u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u043a\u0430\u043a\u00a0\u0440\u0430\u0441\u043f\u0435\u0447\u0430\u0442\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442, \u043d\u043e\u00a0\u043f\u0435\u0447\u0430\u0442\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u044b (\u0441\u0430\u043c\u0438 \u0431\u0443\u043a\u0432\u044b \u0438 \u0437\u043d\u0430\u043a\u0438 \u043f\u0440\u0435\u043f\u0438\u043d\u0430\u043d\u0438\u044f). \u0422\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u0434\u043e \u0442\u0435\u043a\u0441\u0442 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u00a0\u0430\u0431\u0437\u0430\u0446\u044b, \u043f\u043e\u0442\u043e\u043c \u0430\u0431\u0437\u0430\u0446\u044b\u00a0\u2014 \u043d\u0430\u00a0\u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u00a0\u2014 \u0441\u043b\u043e\u0432\u0430, \u0438 \u0441\u043b\u043e\u0432\u0430\u00a0\u2014 \u043d\u0430\u00a0\u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0438 \u0443\u0436\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0430\u00a0\u044d\u043a\u0440\u0430\u043d.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c. \u0412\u043d\u0430\u0447\u0430\u043b\u0435, \u043a\u0430\u043a\u00a0\u0438 \u0432\u00a0\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <code>TextComponent<\/code>. \u041e\u043d \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<p><code>public void add(TextComponent textComponent)<\/code>\u00a0\u2014 \u0433\u0434\u0435 \u043c\u044b \u0432\u00a0\u043a\u043b\u0430\u0441\u0441\u0430\u0445 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430\u0445 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0441\u0442\u0440\u043e\u044f \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0434\u0440\u0435\u0432\u043e\u0432\u0438\u0434\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443.<\/p>\n<p><code>public String getText()<\/code>\u00a0\u2014 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430.<\/p>\n<p><code>public void print()<\/code>\u00a0\u2014 \u0432\u044b\u0432\u043e\u0434 \u043d\u0430\u00a0\u044d\u043a\u0440\u0430\u043d.<\/p>\n<pre><code class=\"java\">public abstract class TextComponent {     public void add(TextComponent textComponent) { throw new UnsupportedOperationException(); } public String getText() { throw new UnsupportedOperationException(); }    public void print() { throw new UnsupportedOperationException(); } }<\/code><\/pre>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441\u00a0\u043a\u043b\u0430\u0441\u0441\u0430 <code>Text<\/code>\u00a0\u2014 \u0441\u0430\u043c\u043e\u0433\u043e \u0433\u043b\u0430\u0432\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u0412\u00a0\u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0430\u0431\u0437\u0430\u0446\u0435\u0432 <code>ArrayList &lt;TextComponent>paragraphs<\/code>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e\u00a0\u0442\u0435\u043a\u0441\u0442 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437\u00a0\u0430\u0431\u0437\u0430\u0446\u0435\u0432. \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>public void setItemComponents()<\/code>\u00a0\u2014 \u0432\u00a0\u043d\u0435\u043c \u0442\u0435\u043a\u0441\u0442 \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u00a0\u0430\u0431\u0437\u0430\u0446\u044b \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u00a0\u0441\u043f\u0438\u0441\u043e\u043a \u0430\u0431\u0437\u0430\u0446\u0435\u0432. \u0422\u0430\u043a\u0436\u0435 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043c\u0435\u0442\u043e\u0434 <code>public void print()<\/code>\u00a0\u2014 \u0437\u0434\u0435\u0441\u044c \u0442\u043e\u0436\u0435 \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>setItemComponents()<\/code>\u00a0\u2014 \u0434\u0435\u043b\u0438\u043c \u0442\u0435\u043a\u0441\u0442 \u043d\u0430\u00a0\u0430\u0431\u0437\u0430\u0446\u044b \u0438 \u043f\u043e\u0442\u043e\u043c \u0434\u043b\u044f\u00a0\u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 (\u0442\u043e \u0435\u0441\u0442\u044c \u0430\u0431\u0437\u0430\u0446\u0430) \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>print()<\/code>.<\/p>\n<pre><code class=\"java\">public class Text extends TextComponent{     ArrayList&lt;TextComponent> paragraphs = new ArrayList&lt;TextComponent>();     String text;      public Text(String text) {         this.text = text;     }      public void add(TextComponent paragraph) {         paragraphs.add(paragraph);     }      public String getText() {         return text;     }      public void setItemComponents() {         String[] result = text.split(\"\\n\");         for (int i = 0; i &lt; result.length; i++) {             paragraphs.add(new Paragraph(result[i]));         }     }      public void print() {         setItemComponents();         Iterator&lt;TextComponent> iterator = paragraphs.iterator();         paragraphs.stream()                 .takeWhile(x -> iterator.hasNext())                 .map(n -> iterator.next())                 .forEach(TextComponent::print);     }  }<\/code><\/pre>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 <code>Paragraph<\/code>\u00a0\u2014 \u0430\u0431\u0437\u0430\u0446. \u041e\u043d \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436 \u043d\u0430\u00a0\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u043a\u043b\u0430\u0441\u0441. \u0417\u0434\u0435\u0441\u044c \u0443\u00a0\u043d\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0439 <code>ArrayList&lt;TextComponent>sentences<\/code>, \u0430\u00a0\u0442\u0430\u043a\u0436\u0435 \u0434\u0440\u0443\u0433\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0430\u0431\u0437\u0430\u0446\u0430 \u043d\u0430\u00a0\u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f (\u043c\u0435\u0442\u043e\u0434 <code>public void setItemComponents()<\/code>). \u0422\u0430\u043a\u0436\u0435 \u043a\u0430\u043a\u00a0\u0438 \u0432\u00a0\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u043c\u0435\u0442\u043e\u0434 <code>public void print()<\/code> \u0434\u0435\u043b\u0438\u0442 \u0442\u0435\u043a\u0441\u0442 \u043d\u0430\u00a0\u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u043f\u043e\u0442\u043e\u043c \u0434\u043b\u044f\u00a0\u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 (\u0442\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f) \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>print()<\/code>.<\/p>\n<pre><code class=\"java\">public class Paragraph extends TextComponent{     ArrayList&lt;TextComponent> sentences = new ArrayList&lt;TextComponent>();     String paragraph;      public Paragraph(String paragraph) {         this.paragraph = paragraph;     }      public void add(TextComponent paragraph) {         sentences.add(paragraph);     }      public String getText() {         return paragraph;     }      public void setItemComponents() {         String[] result = paragraph.split(\"\\\\.\\\\\\\\!\\\\?\");         for (int i = 0; i &lt; result.length; i++) {             sentences.add(new Sentence(result[i]));         }     }      public void print() {         setItemComponents();         Iterator&lt;TextComponent> iterator = sentences.iterator();         sentences.stream()                 .takeWhile(x -> iterator.hasNext())                 .map(n -> iterator.next())                 .forEach(TextComponent::print);         System.out.print(\"\\n\");     }  }<\/code><\/pre>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0434\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 <code>Sentence<\/code> \u0438 <code>World<\/code> \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u00a0\u0431\u0443\u0434\u0443\u00a0\u2014 \u043e\u043d\u0438 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c.<\/p>\n<pre><code class=\"java\">public class Sentence extends TextComponent{     ArrayList&lt;TextComponent> worlds = new ArrayList&lt;TextComponent>();     String sentence;      public Sentence(String sentence) {         this.sentence = sentence;     }      public void add(TextComponent paragraph) {         worlds.add(paragraph);     }      public String getText() {         return sentence;     }      public void setItemComponents() {         String[] result = sentence.split(\" \");         for (int i = 0; i &lt; result.length; i++) {             worlds.add(new World(result[i]));         }     }      public void print() {         setItemComponents();         Iterator&lt;TextComponent> iterator = worlds.iterator();         worlds.stream()                 .takeWhile(x -> iterator.hasNext())                 .map(n -> iterator.next())                 .forEach(TextComponent::print);     } }<\/code><\/pre>\n<pre><code class=\"java\">public class World extends TextComponent{     ArrayList&lt;TextComponent> symbols = new ArrayList&lt;TextComponent>();     String symbol;      public World(String symbol) {         this.symbol = symbol;     }      public void add(TextComponent paragraph) {         symbols.add(paragraph);     }      public String getText() {         return symbol;     }      public void setItemComponents() {         String[] result = symbol.split(\"\");         for (int i = 0; i &lt; result.length; i++) {             symbols.add(new Symbol(result[i]));         }     }      public void print() {         setItemComponents();         Iterator&lt;TextComponent> iterator = symbols.iterator();         symbols.stream()                 .takeWhile(x -> iterator.hasNext())                 .map(n -> iterator.next())                 .forEach(TextComponent::print);         System.out.print(\" \");     } }<\/code><\/pre>\n<p>\u0418 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 <code>Symbol<\/code> (\u0441\u0438\u043c\u0432\u043e\u043b)\u00a0\u2014 \u0441\u0430\u043c\u044b\u0439 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442. \u0412\u00a0\u043d\u0435\u043c \u0432\u00a0\u043c\u0435\u0442\u043e\u0434\u0435 <code>public void print()<\/code> \u043c\u044b \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u043d\u0430\u00a0\u044d\u043a\u0440\u0430\u043d \u0441\u0438\u043c\u0432\u043e\u043b.<\/p>\n<pre><code class=\"java\">public class Symbol extends TextComponent{     String item;      public Symbol(String item) {         this.item = item;     }     public String getText() {         return item;     }      public void print() {         System.out.print(getText()) ;     } }<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448 \u0432\u0435\u0441\u044c \u043a\u043e\u0434. \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441 <code>TestDriveSecond<\/code>, \u0432\u00a0\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0440\u0430\u043d\u0434\u043e\u043c\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u0438 \u0432\u044b\u0437\u043e\u0432\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>print()<\/code> \u0443\u00a0\u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 <code>Text<\/code>. <\/p>\n<pre><code class=\"java\">public class TestDriveSecond {     public static void main(String[] args) {         final String textForPrint =                         \"Occaecat irure commodo labore ullamco est minim aute laborum sint officia consequat cupidatat dolor reprehenderit. Nulla magna amet aliqua incididunt laborum esse tempor aliqua ex esse veniam. Proident tempor voluptate voluptate velit magna et eu aute sint excepteur quis labore in. Sint consectetur sint aliquip minim elit quis elit mollit voluptate sit aute cupidatat.\\n\" +                                 \"Anim eu Lorem aliqua elit enim amet dolore tempor irure ullamco dolore ad fugiat. Deserunt commodo aliquip cillum exercitation exercitation ex velit voluptate mollit sit aute. Fugiat in officia amet est dolore sunt.\\n\" +                                 \"Pariatur amet qui esse fugiat veniam occaecat Lorem exercitation consectetur qui. Magna tempor exercitation laborum sunt minim magna eu mollit laborum ut do sit. Excepteur sunt ullamco nisi officia non labore est magna aute excepteur cillum. Fugiat quis reprehenderit quis quis aliquip consequat ut cillum culpa. Magna pariatur incididunt nisi nostrud esse amet proident. Reprehenderit ad ullamco deserunt amet amet laboris.\\n\" +                                 \"Mollit adipisicing laboris laboris tempor in irure aliquip ullamco laborum cillum sit. Magna id proident commodo culpa magna dolor reprehenderit ad minim. Enim ad est eu fugiat id. Aute id sit aliquip sunt ullamco in magna est consequat culpa magna.\";         Text text = new Text(textForPrint);         text.print();     } }<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/222\/742\/d33\/222742d3321a9d5b98ee24eec6858fa3.png\" width=\"1636\" height=\"250\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/222\/742\/d33\/222742d3321a9d5b98ee24eec6858fa3.png\"\/><\/figure>\n<p>\u0412\u043e\u0442 \u043c\u044b \u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u043d\u0430\u00a0\u0434\u0432\u0443\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f Composite.<\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0432\u0441\u0435\u043c, \u043a\u0442\u043e \u0434\u043e\u0447\u0438\u0442\u0430\u043b \u0434\u043e\u00a0\u043a\u043e\u043d\u0446\u0430. \u0412\u0441\u0435\u043c \u043f\u043e\u043a\u0430!<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/733546\/\"> https:\/\/habr.com\/ru\/articles\/733546\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f Composite (&#171;\u041a\u043e\u043c\u043f\u043e\u043d\u043e\u0432\u0449\u0438\u043a&#187;).<\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441 \u0442\u0435\u043e\u0440\u0438\u0438. <\/p>\n<p>\u041f\u0430\u0442\u0442\u0435\u0440\u043d Composite, \u0438\u0441\u0445\u043e\u0434\u044f \u0443\u0436\u0435 \u0441 \u0441\u0430\u043c\u043e\u0433\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043a\u043e\u043c\u043f\u043e\u043d\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043f\u043e \u0442\u0438\u043f\u0443 &#171;\u0434\u0435\u0440\u0435\u0432\u0430&#187;, \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u043e\u0442 \u0447\u0430\u0441\u0442\u043d\u043e\u0433\u043e \u043a \u0446\u0435\u043b\u043e\u043c\u0443, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c \u0435\u0434\u0438\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e \u0442\u0440\u0430\u043a\u0442\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u044d\u0442\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430. \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0438 \u043c\u0435\u043b\u043a\u0438\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0432 \u0431\u043e\u043b\u0435\u0435 \u043a\u0440\u0443\u043f\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043c\u043e\u0433\u0443\u0442 \u0441\u0442\u0430\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043e\u0439 \u0434\u043b\u044f \u0435\u0449\u0435 \u0431\u043e\u043b\u0435\u0435 \u043a\u0440\u0443\u043f\u043d\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440.<\/p>\n<figure class=\"\"><\/figure>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430.<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0426\u0435\u043d\u0442\u0440\u0430\u043b\u044c\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0438\u043b\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 Component &#8212; \u043e\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0440\u044f\u0434 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438 \u043c\u043e\u0436\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0438\u043b\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0431\u0435\u0437 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0437\u0430\u0434\u0430\u0432\u0430\u043b\u0438 \u043a\u043b\u0430\u0441\u0441\u044b \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0438.<\/p>\n<p>\u041a\u043b\u0430\u0441\u0441 Composite &#8212; \u044d\u0442\u043e \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0434\u0435\u0440\u0435\u0432\u0430, \u043e\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u043e\u043c Component. \u041e\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0430\u0431\u043e\u0440 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 children: Componenntss[]. \u042d\u0442\u043e \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043a\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b-\u043b\u0438\u0441\u0442\u044c\u044f, \u0442\u0430\u043a \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u044b. \u041c\u0435\u0442\u043e\u0434\u044b \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u0435\u0440\u0435\u0430\u0434\u0440\u0435\u0441\u043e\u0432\u044b\u0432\u0430\u044e\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0441\u0432\u043e\u0438\u043c \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c, \u043d\u043e \u0438 \u043c\u043e\u0433\u0443\u0442 \u0447\u0442\u043e-\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u0432\u043e\u0451 \u043a \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0443.<\/p>\n<p>\u041a\u043b\u0430\u0441\u0441 Leaf &#8212; \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0434\u0435\u0440\u0435\u0432\u0430, \u043e\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u043e\u043c Componenta. \u0414\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u041e\u043d \u0442\u0430\u043a\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u044b, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043f\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0443 \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 Component. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043c\u043e\u0433\u0443\u0442 \u043d\u0435 \u0438\u043c\u0435\u0442\u044c \u0441\u043c\u044b\u0441\u043b\u0430 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u0435\u0442\u043e\u0434 add()), \u0432 \u0442\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>\u041a\u043b\u0430\u0441\u0441 Client \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043e\u0431\u0449\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0438\u043b\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 Composite \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u043c\u0443, \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043d\u0435 \u0432\u0430\u0436\u043d\u043e, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0434 \u043d\u0438\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f &#8212; \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438\u043b\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u043e\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0434\u0435\u0440\u0435\u0432\u0430.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043d\u0430\u00a0\u0434\u0432\u0443\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445. <\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0435\u0440\u0432\u044b\u0439.<\/strong> \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0440\u0430\u0441\u043f\u0435\u0447\u0430\u0442\u0430\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u043a\u043d\u0438\u0433\u0438. \u0412\u00a0\u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0438, \u043a\u0430\u043a\u00a0\u0440\u0430\u0437 \u0438 \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u0440\u0435\u0432\u043e\u0432\u0438\u0434\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430. \u041a\u0430\u0436\u0434\u0430\u044f \u0433\u043b\u0430\u0432\u0430 \u043a\u043d\u0438\u0433\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u00a0\u0441\u0435\u0431\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438\u00a0\u2014 \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u044b. \u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a\u00a0\u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043a\u043e\u0434\u0430.<\/p>\n<p>\u0412\u043d\u0430\u0447\u0430\u043b\u0435 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u00a0\u2014 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <code>ContentsComponent<\/code>. \u0412\u00a0\u043d\u0435\u043c \u043c\u044b \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432.<\/p>\n<p><code>public void add(ContentsComponent contentsComponent)<\/code>\u00a0\u2014 \u0432\u00a0\u0434\u0430\u043d\u043d\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u0432\u00a0\u043a\u043b\u0430\u0441\u0441\u0430\u0445 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430\u0445 \u043c\u044b \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043b\u043e\u0433\u0438\u043a\u0443 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f.<\/p>\n<p><code>public String getName()<\/code>\u00a0\u2014 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f\u00a0\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0433\u043b\u0430\u0432\u044b \u0438\u043b\u0438\u00a0\u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u0430.<\/p>\n<p>public Integer getPages()\u00a0\u2014 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f\u00a0\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u043e\u043c\u0435\u0440\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b.<\/p>\n<p><code>public void print()<\/code>\u00a0\u2014 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0432\u00a0\u043a\u043b\u0430\u0441\u0441\u0430\u0445 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432\u044b\u0432\u043e\u0434 \u043d\u0430\u00a0\u044d\u043a\u0440\u0430\u043d \u0433\u043b\u0430\u0432 \u0438 \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u043e\u0432.<\/p>\n<pre><code class=\"java\">public abstract class ContentsComponent {     public void add(ContentsComponent contentsComponent) { throw new UnsupportedOperationException(); } public String getName() { throw new UnsupportedOperationException(); } public Integer getPages() { throw new UnsupportedOperationException(); } public void print() { throw new UnsupportedOperationException(); } }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441 <code>Contents<\/code> \u0438 \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u0435\u0433\u043e \u043e\u0442 <code>ContentsComponent<\/code>. \u042d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0440\u043e\u043b\u044c \u043d\u0430\u0448\u0438\u0445 \u0433\u043b\u0430\u0432, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0443\u0436\u0435 \u0431\u043e\u043b\u0435\u0435 \u043c\u0435\u043b\u043a\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 (\u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u043e\u0432)\u00a0\u2014 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c <code>ArrayList &lt;\u0421ontentsComponents> contentsComponents.<\/code> \u0422\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u043b\u044f <code>name<\/code> \u0438 <code>pages<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u0437\u0430\u00a0\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0433\u043b\u0430\u0432\u044b \u0438 \u043d\u043e\u043c\u0435\u0440\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b.<\/p>\n<p>\u041f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043c\u0435\u0442\u043e\u0434 <code>public void print()<\/code>\u00a0\u2014 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0433\u043b\u0430\u0432\u044b \u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u0430\u00a0\u0442\u0430\u043a\u0436\u0435 \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0442\u044c \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 <code>contentsComponents<\/code> \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0443\u00a0\u043d\u0438\u0445 \u0441\u0432\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 <code>print()<\/code>.<\/p>\n<pre><code class=\"java\">public class Contents extends ContentsComponent { ArrayList&lt;ContentsComponent> contentsComponents = new ArrayList&lt;ContentsComponent>(); String name; Integer pages;  public Contents(String name, Integer pages) { this.name = name; this.pages = pages; }   public void add(ContentsComponent contentsComponent) { contentsComponents.add(contentsComponent); }  public String getName() { return name; }   public Integer getPages() { return pages; }   public void print() { System.out.print(\"\\n\" + getName()); for (int i = 0; i &lt; 70-getName().length(); i++) { System.out.print(\".\"); } System.out.println(getPages());  Iterator&lt;ContentsComponent> iterator = contentsComponents.iterator(); contentsComponents.stream() .takeWhile(x -> iterator.hasNext()) .map(n -> iterator.next()) .forEach(ContentsComponent::print);  } }<\/code><\/pre>\n<p>\u041f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043a\u043b\u0430\u0441\u0441\u00a0\u2014 <code>ContentsItem<\/code>. \u042d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u0442\u0430\u043a\u0436\u0435 \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u043e\u0442\u00a0<code>ContentsComponent<\/code> \u0438 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u0437\u0430\u00a0\u043d\u0430\u0448\u0438 \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u044b. \u0412\u00a0\u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0442\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u043f\u043e\u043b\u044f <code>name<\/code> \u0438 pages(\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u0430 \u0438 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b), \u043d\u043e\u00a0\u0443\u0436\u0435 \u043d\u0435\u0442\u0443 \u0441\u043f\u0438\u0441\u043a\u0430 \u043d\u043e\u0432\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0442\u0430\u043a \u043a\u0430\u043a\u00a0\u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0443\u00a0\u043d\u0430\u0441 \u043a\u0430\u043a\u00a0\u043b\u0438\u0441\u0442 \u043d\u0430\u00a0\u0434\u0435\u0440\u0435\u0432\u0435\u00a0\u2014 \u043d\u0435\u00a0\u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432\u00a0\u0441\u0435\u0431\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0434\u043b\u044f\u00a0\u043d\u0435\u0433\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043c\u0435\u0442\u043e\u0434 <code>public void print()<\/code>\u00a0\u2014 \u0433\u0434\u0435 \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u0430 \u0438 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b.<\/p>\n<pre><code class=\"java\">public class ContentsItem extends ContentsComponent { String name; Integer pages; public ContentsItem(String name, Integer pages) {  this.name = name; this.pages = pages; }    public String getName() { return name; }    public Integer getPages() { return pages; }     public void print() { System.out.print(\"  \" + getName()); for (int i = 0; i &lt; 68-getName().length(); i++) { System.out.print(\".\"); } System.out.println(getPages()); } } <\/code><\/pre>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043a\u043b\u0430\u0441\u0441 <code>Book<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c <code>ContentsComponent contents<\/code>, \u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0430\u0448\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>public void printContents()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u043d\u0430\u00a0\u043f\u0435\u0447\u0430\u0442\u044c.<\/p>\n<pre><code class=\"java\">public class Book { ContentsComponent contents;  public Book(ContentsComponent contents) { this.contents = contents; }   public void printContents() { contents.print(); } }<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0441\u044c \u043d\u0430\u0448 \u043a\u043e\u0434, \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441 <code>TestDrive<\/code>, \u0432\u00a0\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0434\u043b\u044f\u00a0\u043a\u043d\u0438\u0433\u0438.<\/p>\n<p>\u0412\u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0430\u043c\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435, \u043f\u043e\u0442\u043e\u043c \u0433\u043b\u0430\u0432\u044b \u0438 \u043f\u043e\u0442\u043e\u043c \u043a\u0430\u0436\u0434\u043e\u0439 \u0433\u043b\u0430\u0432\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u044b. <\/p>\n<pre><code class=\"java\">public class TestDrive {            public static void main(String[] args) {         ContentsComponent contents = new Contents(\"Contents \", 1);          ContentsComponent introduction = new Contents(\"1. Introduction \", 1);         ContentsComponent creatingAndDestroyingObject = new Contents(\"2. Creating and destroying object \", 5);         ContentsComponent methodsCommonToAllObject = new Contents(\"3. Methods common to all object \", 37);         ContentsComponent classesAndInterfaces = new Contents(\"4. Classes and interfaces \", 73);          contents.add(introduction);         contents.add(creatingAndDestroyingObject);         contents.add(methodsCommonToAllObject);         contents.add(classesAndInterfaces);          creatingAndDestroyingObject.add(new ContentsItem(                 \"2.1 Consider static factory methods instead of constructors \",                 5         ));         creatingAndDestroyingObject.add(new ContentsItem(                 \"2.2 Consider a builder when faced with many constructor parameters \",                 10         ));         creatingAndDestroyingObject.add(new ContentsItem(                 \"2.3 Enforce the singleton property with a private constructor \",                 17         ));          methodsCommonToAllObject.add(new ContentsItem(                 \"3.1 Obey the general contract when overriding equals \",                 37         ));          methodsCommonToAllObject.add(new ContentsItem(                 \"3.2 Always override hashCode when you override equals \",                 50         ));          classesAndInterfaces.add(new ContentsItem(                 \"4.1 Minimize the accessibility of classes and members \",                 73         ));         classesAndInterfaces.add(new ContentsItem(                 \"4.2 in public classes, use accessor methods, not public fields \",                 78         ));         classesAndInterfaces.add(new ContentsItem(                 \"4.3 Minimize mutability \",                 80         ));          System.out.println(\"\\\"Effective Java\\\" Joshua Bloch, 2018\");          Book book = new Book(contents);          book.printContents();      }      }<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0432\u044b\u0432\u043e\u0434 \u043d\u0430\u00a0\u044d\u043a\u0440\u0430\u043d.<\/p>\n<figure class=\"full-width\"><\/figure>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u0432\u0442\u043e\u0440\u043e\u0439.<\/strong> \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0443\u00a0\u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u043a\u0430\u043a\u00a0\u0440\u0430\u0441\u043f\u0435\u0447\u0430\u0442\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442, \u043d\u043e\u00a0\u043f\u0435\u0447\u0430\u0442\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u044b (\u0441\u0430\u043c\u0438 \u0431\u0443\u043a\u0432\u044b \u0438 \u0437\u043d\u0430\u043a\u0438 \u043f\u0440\u0435\u043f\u0438\u043d\u0430\u043d\u0438\u044f). \u0422\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u0434\u043e \u0442\u0435\u043a\u0441\u0442 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u00a0\u0430\u0431\u0437\u0430\u0446\u044b, \u043f\u043e\u0442\u043e\u043c \u0430\u0431\u0437\u0430\u0446\u044b\u00a0\u2014 \u043d\u0430\u00a0\u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u00a0\u2014 \u0441\u043b\u043e\u0432\u0430, \u0438 \u0441\u043b\u043e\u0432\u0430\u00a0\u2014 \u043d\u0430\u00a0\u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0438 \u0443\u0436\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0430\u00a0\u044d\u043a\u0440\u0430\u043d.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c. \u0412\u043d\u0430\u0447\u0430\u043b\u0435, \u043a\u0430\u043a\u00a0\u0438 \u0432\u00a0\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <code>TextComponent<\/code>. \u041e\u043d \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<p><code>public void add(TextComponent textComponent)<\/code>\u00a0\u2014 \u0433\u0434\u0435 \u043c\u044b \u0432\u00a0\u043a\u043b\u0430\u0441\u0441\u0430\u0445 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430\u0445 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0441\u0442\u0440\u043e\u044f \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0434\u0440\u0435\u0432\u043e\u0432\u0438\u0434\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443.<\/p>\n<p><code>public String getText()<\/code>\u00a0\u2014 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430.<\/p>\n<p><code>public void print()<\/code>\u00a0\u2014 \u0432\u044b\u0432\u043e\u0434 \u043d\u0430\u00a0\u044d\u043a\u0440\u0430\u043d.<\/p>\n<pre><code class=\"java\">public abstract class TextComponent {     public void add(TextComponent textComponent) { throw new UnsupportedOperationException(); } public String getText() { throw new UnsupportedOperationException(); }    public void print() { throw new UnsupportedOperationException(); } }<\/code><\/pre>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441\u00a0\u043a\u043b\u0430\u0441\u0441\u0430 <code>Text<\/code>\u00a0\u2014 \u0441\u0430\u043c\u043e\u0433\u043e \u0433\u043b\u0430\u0432\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u0412\u00a0\u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0430\u0431\u0437\u0430\u0446\u0435\u0432 <code>ArrayList &lt;TextComponent>paragraphs<\/code>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e\u00a0\u0442\u0435\u043a\u0441\u0442 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437\u00a0\u0430\u0431\u0437\u0430\u0446\u0435\u0432. \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>public void setItemComponents()<\/code>\u00a0\u2014 \u0432\u00a0\u043d\u0435\u043c \u0442\u0435\u043a\u0441\u0442 \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u00a0\u0430\u0431\u0437\u0430\u0446\u044b \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u00a0\u0441\u043f\u0438\u0441\u043e\u043a \u0430\u0431\u0437\u0430\u0446\u0435\u0432. \u0422\u0430\u043a\u0436\u0435 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043c\u0435\u0442\u043e\u0434 <code>public void print()<\/code>\u00a0\u2014 \u0437\u0434\u0435\u0441\u044c \u0442\u043e\u0436\u0435 \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>setItemComponents()<\/code>\u00a0\u2014 \u0434\u0435\u043b\u0438\u043c \u0442\u0435\u043a\u0441\u0442 \u043d\u0430\u00a0\u0430\u0431\u0437\u0430\u0446\u044b \u0438 \u043f\u043e\u0442\u043e\u043c \u0434\u043b\u044f\u00a0\u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 (\u0442\u043e \u0435\u0441\u0442\u044c \u0430\u0431\u0437\u0430\u0446\u0430) \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>print()<\/code>.<\/p>\n<pre><code class=\"java\">public class Text extends TextComponent{     ArrayList&lt;TextComponent> paragraphs = new ArrayList&lt;TextComponent>();     String text;      public Text(String text) {         this.text = text;     }      public void add(TextComponent paragraph) {         paragraphs.add(paragraph);     }      public String getText() {         return text;     }      public void setItemComponents() {         String[] result = text.split(\"\\n\");         for (int i = 0; i &lt; result.length; i++) {             paragraphs.add(new Paragraph(result[i]));         }     }      public void print() {         setItemComponents();         Iterator&lt;TextComponent> iterator = paragraphs.iterator();  <\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-393089","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/393089","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=393089"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/393089\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=393089"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=393089"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=393089"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}