{"id":312864,"date":"2020-11-10T09:00:26","date_gmt":"2020-11-10T09:00:26","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=312864"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=312864","title":{"rendered":"\u041e\u041e\u041f \u0432 \u044f\u0437\u044b\u043a\u0435 R (\u0447\u0430\u0441\u0442\u044c 2): R6 \u043a\u043b\u0430\u0441\u0441\u044b"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<p>\u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 <a href=\"https:\/\/habr.com\/ru\/post\/453964\/\">\u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438<\/a> \u043c\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438 S3 \u043a\u043b\u0430\u0441\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c\u0438 \u0432 \u044f\u0437\u044b\u043a\u0435 R. <\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c\u0441\u044f \u0441 R6 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0451\u043d\u043d\u044b\u0435 \u043a \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e.<\/p>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/bo\/ct\/yv\/boctyvkro_bo7tyi4n3ckrka4eu.png\" width=\"80%\"><\/div>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h1 id=\"soderzhanie\">\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/h1>\n<p>  <\/p>\n<p><em>\u0415\u0441\u043b\u0438 \u0432\u044b \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442\u0435\u0441\u044c \u0430\u043d\u0430\u043b\u0438\u0437\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u0430\u043c \u0431\u0443\u0434\u0443\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b \u043c\u043e\u0438 <a href=\"https:\/\/t.me\/R4marketing\" rel=\"nofollow\">telegram<\/a> \u0438 <a href=\"https:\/\/www.youtube.com\/R4marketing\/?sub_confirmation=1\" rel=\"nofollow\">youtube<\/a> \u043a\u0430\u043d\u0430\u043b\u044b. \u0411\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u044b \u044f\u0437\u044b\u043a\u0443 R.<\/em><\/p>\n<p>  <\/p>\n<ol>\n<li><a href=\"#vvedenie\">\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/a><\/li>\n<li><a href=\"#pravila-imenovaniya\">\u041f\u0440\u0430\u0432\u0438\u043b\u0430 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f<\/a><\/li>\n<li><a href=\"#sozdayom-sobstvennyy-klass\">\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441<\/a><\/li>\n<li><a href=\"#cepochka-metodov\">\u0426\u0435\u043f\u043e\u0447\u043a\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432<\/a><\/li>\n<li><a href=\"#metody-initialize-i-print\">\u041c\u0435\u0442\u043e\u0434\u044b $initialize() \u0438 $print()<\/a><\/li>\n<li><a href=\"#dobavlenie-novyh-svoystv-i-metodov-v-klass-posle-ego-opredelenie-metod-set\">\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u044b\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432 \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u0441\u043b\u0435 \u0435\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435, \u043c\u0435\u0442\u043e\u0434 $set()<\/a><\/li>\n<li><a href=\"#nasledovanie\">\u041d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435<\/a><\/li>\n<li><a href=\"#privatnye-metody-i-svoystva\">\u041f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430<\/a><\/li>\n<li><a href=\"#aktivnye-metody\">\u0410\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b<\/a><\/li>\n<li><a href=\"#finalizator-klassa\">\u0424\u0438\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u043a\u043b\u0430\u0441\u0441\u0430<\/a><\/li>\n<li><a href=\"#dobavlenie-r6-klassov-v-paket\">\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 R6 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0432 \u043f\u0430\u043a\u0435\u0442<\/a><\/li>\n<li><a href=\"#poleznye-ssylki\">\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438<\/a><\/li>\n<li><a href=\"#zaklyuchenie\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/a><\/li>\n<\/ol>\n<p>  <\/p>\n<h1 id=\"vvedenie\">\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h1>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u0442\u0435\u0440\u043c\u0438\u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e \u2014 \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0438 \u043d\u0430 \u0435\u0433\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430\u0445, \u0442.\u0435. \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0438, \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u044f\u0446\u0438\u0438 \u0438 \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c\u0435.<\/p>\n<p>  <\/p>\n<p>R6 \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c Python, \u0438 \u0442\u0435\u043c \u043a\u0442\u043e \u043f\u0440\u0438\u0432\u044b\u043a \u043a \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u043c\u0443 \u041e\u041e\u041f. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 S3 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0443 R6 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u044b \u043a \u0441\u0430\u043c\u0438\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0443 S3 \u0432\u0441\u0451 \u0441\u0442\u0440\u043e\u0438\u0442\u0441\u044f \u043d\u0430 \u043e\u0431\u043e\u0431\u0449\u0451\u043d\u043d\u044b\u0445 <em>(generic)<\/em> \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445.<\/p>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u0432\u0441\u0451-\u0442\u0430\u043a\u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0433\u043b\u043e\u0441\u0441\u0430\u0440\u0438\u0439 \u043f\u043e \u041e\u041e\u041f \u044f \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044e:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/000\/ad5\/a9a\/000ad5a9a7db69686c7684ffca920ce3.png\"><\/p>\n<p>  <\/p>\n<ul>\n<li>\u041a\u043b\u0430\u0441\u0441 \u2014 \u044d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u043e\u0442, \u0441\u043e\u0431\u0430\u043a\u0430, \u0430\u0432\u0442\u043e\u043c\u043e\u0431\u0438\u043b\u044c \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<\/li>\n<li>\u042d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u2014 \u0435\u0441\u043b\u0438 \u043a\u043b\u0430\u0441\u0441 \u044d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0443\u0441\u0442\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u0442, \u0442\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u044d\u0442\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0443. \u0422.\u0435. \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0442\u043e\u0432, \u043f\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0440\u0430\u043d\u0435\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u0443.<\/li>\n<li>\u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u2014 \u044d\u0442\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u0440\u0430\u043d\u044f\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043a\u0430\u0436\u0434\u043e\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0435 \u043a\u043b\u0430\u0441\u0441\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043b\u0438\u0447\u043a\u0430 \u0438 \u043f\u043e\u0440\u043e\u0434\u0430 \u043a\u043e\u0442\u0430.<\/li>\n<li>\u041c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0430 \u2014 \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430, \u043d\u0443 \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u043a\u043e\u0442 \u043c\u043e\u0436\u0435\u0442 \u0435\u0441\u0442\u044c, \u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435, \u0432\u0441\u0451 \u044d\u0442\u043e \u0431\u0443\u0434\u0443\u0442 \u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u044b.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 R6 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438 \u0432\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043e\u0434\u043d\u043e\u0438\u043c\u0451\u043d\u043d\u044b\u0439 \u043f\u0430\u043a\u0435\u0442 <code>R6<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"r\">install.packages(&quot;R6&quot;) library(R6)<\/code><\/pre>\n<p>  <\/p>\n<h1 id=\"pravila-imenovaniya\">\u041f\u0440\u0430\u0432\u0438\u043b\u0430 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f<\/h1>\n<p>  <\/p>\n<p>\u0412\u0430\u043c \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0430\u0432\u0438\u043b, \u043d\u043e \u043e\u043d\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u0431\u0449\u0435\u043f\u0440\u0438\u043d\u044f\u0442\u044b\u043c\u0438:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u0418\u043c\u0435\u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0437\u0430\u0434\u0430\u044e\u0442\u0441\u044f \u0432 <code>UpperCamelCase<\/code>.<\/li>\n<li>\u0418\u043c\u0435\u043d\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0438 \u0435\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0437\u0430\u0434\u0430\u044e\u0442\u0441\u044f \u0432 <code>snake_case<\/code>.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0422\u0430\u043a \u0436\u0435 \u043a\u0430\u043a \u0438 \u0432 Python, \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0434\u0440\u0443\u0433\u0438\u043c \u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e <code>self$method()<\/code>.<\/p>\n<p>  <\/p>\n<h1 id=\"sozdayom-sobstvennyy-klass\">\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441<\/h1>\n<p>  <\/p>\n<p>\u0418\u0437 \u043f\u0430\u043a\u0435\u0442\u0430 <code>R6<\/code> \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u043d\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>R6Class()<\/code>. \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0435\u0451 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b:<\/p>\n<p>  <\/p>\n<ul>\n<li><code>classname<\/code> \u2014 \u0438\u043c\u044f \u043a\u043b\u0430\u0441\u0441\u0430, \u0434\u043e\u043b\u0436\u043d\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u044b \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0435 \u043a\u043b\u0430\u0441\u0441;<\/li>\n<li><code>public<\/code> \u2014 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a (<code>list()<\/code>) \u0441 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 \u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u0430.<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"r\">library(R6)  # \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043b\u0430\u0441\u0441 Cat Cat &lt;- R6Class(classname = &quot;Cat&quot;,                public = list(                  name  = &quot;Tom&quot;,                  breed = &quot;Persian&quot;,                  age   = 3,                  rename = function(name = NULL) {                    self$name &lt;- name                    invisible(self)                  },                  add_year = function(ages = 1) {                    self$age &lt;- age + ages                    invisible(self)                  }                )              )<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043b\u0430\u0441\u0441 <code>Cat<\/code>, \u0441 \u0442\u0440\u0435\u043c\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 <code>name<\/code>, <code>breed<\/code> \u0438 <code>age<\/code>, \u0438 \u0434\u0432\u0443\u043c\u044f \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 <code>$rename()<\/code> \u0438 <code>$add_year()<\/code>. \u041c\u0435\u0442\u043e\u0434 <code>$rename()<\/code> \u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>name<\/code>, \u043a\u0430\u043a \u044f \u043f\u0438\u0441\u0430\u043b \u0440\u0430\u043d\u0435\u0435 \u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0443 \u043c\u0435\u0442\u043e\u0434 \u043c\u043e\u0436\u0435\u0442 \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u0447\u0435\u0440\u0435\u0437 <code>self$name<\/code>, \u0430 \u043c\u0435\u0442\u043e\u0434 <code>$add_year()<\/code> \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0432\u043e\u0437\u0440\u0430\u0441\u0442 \u043a\u043e\u0442\u0430 \u043d\u0430 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043b\u0435\u0442.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>$new()<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"r\"># \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 Cat tom &lt;- Cat$new() # \u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 tom<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">&lt;Cat&gt;   Public:     add_year: function (ages = 1)      age: 3     breed: Persian     clone: function (deep = FALSE)      name: Tom     rename: function (name = NULL) <\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>$rename()<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"r\"># \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434 rename tom$rename('Tommy') # \u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 tom<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">&lt;Cat&gt;   Public:     add_year: function (ages = 1)      age: 3     breed: Persian     clone: function (deep = FALSE)      name: Tommy     rename: function (name = NULL) <\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>R6<\/code> \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043c\u0435\u043d\u044f\u044e\u0442 \u0441\u0432\u043e\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043d\u0430 \u043b\u0435\u0442\u0443, \u0442.\u0435. \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u043f\u0438\u0438 \u044d\u0442\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u0422.\u043a. \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043b\u0430\u0441\u0441 \u0441 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 \u0442\u043e \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u043a \u043d\u0438\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u0432\u043d\u0435 \u043a\u043b\u0430\u0441\u0441\u0430, \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043c\u043e\u0436\u0435\u043c \u0438\u0445 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c.<\/p>\n<p>  <\/p>\n<pre><code class=\"r\"># \u043c\u0435\u043d\u044f\u0435\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e tom$name &lt;- 'Tom' # \u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 tom<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">&lt;Cat&gt;   Public:     add_year: function (ages = 1)      age: 3     breed: Persian     clone: function (deep = FALSE)      name: Tom     rename: function (name = NULL) <\/code><\/pre>\n<p>  <\/p>\n<h1 id=\"cepochka-metodov\">\u0426\u0435\u043f\u043e\u0447\u043a\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432<\/h1>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u043e\u0431\u0440\u0430\u0442\u0438\u043b\u0438 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0442\u043e \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043c\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0441\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 <code>self<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>invisible(self)<\/code>. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0431\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u043c\u0435\u0442\u043e\u0434\u043e\u0432:<\/p>\n<p>  <\/p>\n<pre><code class=\"r\"># \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 tom$add_year(1)$add_year(3) # \u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 tom<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">&lt;Cat&gt;   Public:     add_year: function (ages = 1)      age: 7     breed: Persian     clone: function (deep = FALSE)      name: Tom     rename: function (name = NULL) <\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u043f\u044f\u0442\u044c \u0436\u0435 \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0445\u043e\u0440\u043e\u0448\u043e \u0437\u043d\u0430\u043a\u043e\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c Python \u0438 JavaScript.<\/p>\n<p>  <\/p>\n<h1 id=\"metody-initialize-i-print\">\u041c\u0435\u0442\u043e\u0434\u044b $initialize() \u0438 $print()<\/h1>\n<p>  <\/p>\n<p>\u0412\u0430\u0436\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0431\u0443\u0434\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 R6 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434\u044b <code>$initialize()<\/code> \u0438 <code>$print()<\/code>.<\/p>\n<p>  <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 $initialize() \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 <code>$new()<\/code>, \u0442.\u0435. \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0435\u0433\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c \u0432 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u043c\u044f, \u043f\u043e\u0440\u043e\u0434\u0443 \u0438 \u0432\u043e\u0437\u0440\u0430\u0441\u0442 \u043a\u043e\u0442\u0430.<\/p>\n<p>  <\/p>\n<p><code>$print()<\/code> \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \u043f\u0435\u0447\u0430\u0442\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438.<\/p>\n<p>  <\/p>\n<pre><code class=\"r\"># \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043b\u0430\u0441\u0441 Cat Cat &lt;- R6Class(classname = &quot;Cat&quot;,                public = list(                  name  = NA,                  breed = NA,                  age   = 0,                  initialize = function(name, breed, age) {                    self$name  &lt;- name                    self$breed &lt;- breed                    self$age   &lt;- age                  },                   print = function(...) {                    cat(&quot;&lt;Cat&gt;: \\n&quot;)                    cat(&quot;  Name: &quot;, self$name, &quot;\\n&quot;, sep = &quot;&quot;)                    cat(&quot;  Age:  &quot;, self$age, &quot;\\n&quot;, sep = &quot;&quot;)                    cat(&quot;  Breed:  &quot;, self$breed, &quot;\\n&quot;, sep = &quot;&quot;)                    invisible(self)                  },                  rename = function(name = NULL) {                    self$name &lt;- name                    invisible(self)                  },                  add_year = function(ages = 1) {                    self$age &lt;- self$age + ages                    invisible(self)                  }                ) )  # \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 tom &lt;- Cat$new(name = 'Tom',                 breed = 'Scottish fold',                 age = 1)  # \u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 tom<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">&lt;Cat&gt;:    Name: Tom   Age:  1   Breed:  Scottish fold<\/code><\/pre>\n<p>  <\/p>\n<h1 id=\"dobavlenie-novyh-svoystv-i-metodov-v-klass-posle-ego-opredelenie-metod-set\">\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u044b\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432 \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u0441\u043b\u0435 \u0435\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435, \u043c\u0435\u0442\u043e\u0434 $set()<\/h1>\n<p>  <\/p>\n<p>\u0414\u0430\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u0432\u044b \u0432 \u043b\u044e\u0431\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043d\u0435\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438\u043b\u0438 \u043c\u0435\u0442\u043e\u0434\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434 <code>$set()<\/code> \u0438 \u0443\u043a\u0430\u0437\u0430\u0432 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>  <\/p>\n<p>\u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043b\u0430\u0441\u0441 \u0441 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0442\u043e\u0434 <code>$set()<\/code> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u044b <code>$rename()<\/code> \u0438 <code>$add_year()<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"r\"># \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043b\u0430\u0441\u0441 Cat Cat &lt;- R6Class(classname = &quot;Cat&quot;,                public = list(                  name  = NA,                  breed = NA,                  age   = 0,                  initialize = function(name, breed, age) {                    self$name  &lt;- name                    self$breed &lt;- breed                    self$age   &lt;- age                  },                   print = function(...) {                    cat(&quot;&lt;Cat&gt;: \\n&quot;)                    cat(&quot;  Name: &quot;, self$name, &quot;\\n&quot;, sep = &quot;&quot;)                    cat(&quot;  Age:  &quot;, self$age, &quot;\\n&quot;, sep = &quot;&quot;)                    cat(&quot;  Breed:  &quot;, self$breed, &quot;\\n&quot;, sep = &quot;&quot;)                    invisible(self)                  }                ) )  # \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 rename Cat$set( 'public',           'rename',           function(name = NULL)             {             self$name &lt;- name             invisible(self) })  # \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 add_year Cat$set( 'public',           'add_year',           function(ages = 1) {            self$age &lt;- self$age + ages            invisible(self)          })<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u044d\u0442\u043e\u043c, \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043e \u0438\u0445 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u043a\u043b\u0430\u0441\u0441\u0430, \u0430 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0442\u044c\u0441\u044f \u043b\u0438\u0448\u044c \u043d\u0430 \u0442\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u043a\u043b\u0430\u0441\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u043f\u043e\u0441\u043b\u0435 \u0438\u0445 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432 \u043a\u043b\u0430\u0441\u0441.<\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u043f\u0440\u0435\u0442\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0440\u0438 \u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>lock_class = TRUE<\/code>. \u0412 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u044d\u0442\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c, \u0438 \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u043c\u0435\u0442\u043e\u0434\u043e\u043c <code>$unlock()<\/code>, \u0438 \u043e\u043f\u044f\u0442\u044c \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u043e\u043c <code>$lock()<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"r\"># \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043b\u0430\u0441\u0441 \u0441 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u043e\u0439 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432 Simple &lt;- R6Class(&quot;Simple&quot;,   public = list(     x = 1,     getx = function() self$x   ),   lock_class = TRUE )  # \u041f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443 Simple$set(&quot;public&quot;, &quot;y&quot;, 2)  # \u0420\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c \u043a\u043b\u0430\u0441\u0441 Simple$unlock()  # \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0430 Simple$set(&quot;public&quot;, &quot;y&quot;, 2)  # \u041f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c \u043a\u043b\u0430\u0441\u0441 Simple$lock()<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0432\u0437\u044f\u0442 \u0438\u0437 <a href=\"https:\/\/r6.r-lib.org\/articles\/Introduction.html#adding-members-to-an-existing-class\" rel=\"nofollow\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a> \u043a \u043f\u0430\u043a\u0435\u0442\u0443 R6, \u0430\u0432\u0442\u043e\u0440 Winston Chang<\/p><\/blockquote>\n<p>  <\/p>\n<h1 id=\"nasledovanie\">\u041d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435<\/h1>\n<p>  <\/p>\n<p>R6 \u043a\u043b\u0430\u0441\u0441\u044b \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9D%D0%B0%D1%81%D0%BB%D0%B5%D0%B4%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5_(%D0%BF%D1%80%D0%BE%D0%B3%D1%80%D0%B0%D0%BC%D0%BC%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5)\" rel=\"nofollow\">\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f<\/a>, \u0442.\u0435. \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0443\u043f\u0435\u0440 \u043a\u043b\u0430\u0441\u0441\u044b \u0438 \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043e\u0442 \u0441\u0443\u043f\u0435\u0440 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430. \u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0441\u0443\u043f\u0435\u0440 \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/9e7\/6ca\/743\/9e76ca7436a83e7797abfde8f6e34fe7.png\"><\/p>\n<p>  <\/p>\n<p>\u041d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u043a\u043b\u0430\u0441\u0441 &quot;\u0416\u0438\u0432\u043e\u0442\u043d\u044b\u0435&quot; \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0433\u043b\u0430\u0432\u043d\u044b\u043c \u0441\u0443\u043f\u0435\u0440 \u043a\u043b\u0430\u0441\u0441\u043e\u043c, \u0435\u0433\u043e \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u043e\u043c \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f &quot;\u0414\u043e\u043c\u0430\u0448\u043d\u0438\u0435 \u0436\u0438\u0432\u043e\u0442\u043d\u044b\u0435&quot; \u0438 &quot;\u0414\u0438\u043a\u0438\u0435 \u0436\u0438\u0432\u043e\u0442\u043d\u044b\u0435&quot;, \u0442.\u0435. \u043e\u043d\u0438 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044e\u0442 \u0432\u0441\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0430 (\u0448\u0430\u0431\u043b\u043e\u043d\u0430) \u0436\u0438\u0432\u043e\u0442\u043d\u044b\u0435, \u043d\u043e \u043c\u043e\u0433\u0443\u0442 \u0438\u0445 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c, \u0430 \u0442\u0430\u043a \u0436\u0435 \u043c\u043e\u0433\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0441\u0432\u043e\u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u044b &quot;\u041a\u043e\u0442&quot; \u0438 &quot;\u0421\u043e\u0431\u0430\u043a\u0430&quot;, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u043b\u0430\u0441\u0441 &quot;\u0414\u043e\u043c\u0430\u0448\u043d\u0438\u0435 \u0436\u0438\u0432\u043e\u0442\u043d\u044b\u0435&quot; \u0443\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u043c, \u0442.\u0435. \u0441\u0443\u043f\u0435\u0440 \u043a\u043b\u0430\u0441\u0441\u043e\u043c. \u0422\u0430\u043a \u0436\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043b\u0430\u0441\u0441\u044b &quot;\u041e\u043b\u0435\u043d\u044c&quot; \u0438 &quot;\u041c\u0435\u0434\u0432\u0435\u0434\u044c&quot;, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u0443\u043f\u0435\u0440 \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u0431\u0443\u0434\u0435\u0442 &quot;\u0414\u0438\u043a\u0438\u0435 \u0436\u0438\u0432\u043e\u0442\u043d\u044b\u0435&quot;. <\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u0443 \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u043f\u043e\u0440\u043e\u0434\u0430\u043c\u0438 \u043a\u043e\u0442\u043e\u0432, \u0441\u043e\u0431\u0430\u043a, \u043e\u043b\u0435\u043d\u0435\u0439 \u0438 \u043c\u0435\u0434\u0432\u0435\u0434\u0435\u0439.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9D%D0%B0%D1%81%D0%BB%D0%B5%D0%B4%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5_(%D0%BF%D1%80%D0%BE%D0%B3%D1%80%D0%B0%D0%BC%D0%BC%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5)\" rel=\"nofollow\">\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f<\/a> \u0432 R6 \u043a\u043b\u0430\u0441\u0441\u0430\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>inherit<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"r\">library(R6)  # \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u0443\u043f\u0435\u0440 \u043a\u043b\u0430\u0441\u0441 Cat Cat &lt;- R6Class(classname = &quot;Cat&quot;,                public = list(                  name  = NA,                  breed = NA,                  age   = 3,                  initialize = function(name, breed, age) {                    self$name  &lt;- name                    self$breed &lt;- breed                    self$age   &lt;- age                  },                  rename = function(name = NULL) {                    self$name &lt;- name                    invisible(self)                  },                  add_year = function(ages = 1) {                    self$age &lt;- self$age + ages                    invisible(self)                  }                )              )  # \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441 ScottishCat ScottishCat &lt;- R6Class(&quot;ScottishCat&quot;,                         inherit = Cat,                        public = list(                          breed = &quot;Scottish Fold&quot;,                          add_year = function() {                               cat(&quot;\u0423\u0432\u0435\u043b\u0438\u0447\u0438\u043b\u0438 \u0432\u043e\u0437\u0440\u0430\u0441\u0442 &quot;, self$name, &quot; \u043d\u0430 1 \u0433\u043e\u0434&quot;, sep = &quot;&quot;)                               super$add_year(ages = 1)                          },                          initialize = function(name,  age, breed = &quot;Scottish Fold&quot;) {                               self$name  &lt;- name                               self$breed &lt;- breed                               self$age   &lt;- age                                }                              ) )  # \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 scottish &lt;- ScottishCat$new(name = 'Arnold', age = 1)  # \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u0430 scottish$add_year()<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0441\u0443\u043f\u0435\u0440 \u043a\u043b\u0430\u0441\u0441 <code>Cat<\/code>, \u0438 \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441 <code>ScottishCat<\/code>. \u0412 \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u0435 \u043c\u044b \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 <code>$add_year()<\/code>, \u0442\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u0442 \u0441\u0443\u043f\u0435\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u0435\u0442\u043e\u0434\u044b \u043e\u0431\u0440\u0430\u0449\u0430\u044f\u0441\u044c \u043a \u043d\u0438\u043c \u0447\u0435\u0440\u0435\u0437 <code>super$method()<\/code>.<\/p>\n<p>  <\/p>\n<h1 id=\"privatnye-metody-i-svoystva\">\u041f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430<\/h1>\n<p>  <\/p>\n<p>\u0412 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>public<\/code> \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>R6Class()<\/code> \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u0441 \u043e\u0431\u0449\u0438\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c, \u0442.\u0435. \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043a\u0430\u043a \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430, \u0442\u0430\u043a \u0438 \u0437\u0430 \u0435\u0433\u043e \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438. <\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438 \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430. \u0422\u0430\u043a\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>private<\/code>, \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 <code>private$methode_name<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"r\">library(R6)  # \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043b\u0430\u0441\u0441   User &lt;- R6Class('User',                  public = list(                   name = NA,                   initialize = function(name, password, credits = 100) {                     self$name        &lt;- name                     private$password &lt;- password                     private$credits  &lt;- credits                   },                   print = function(...) {                     cat(&quot;&lt;User&gt;: &quot;, self$name, sep='')                   },                   get_credits = function() {                     cat(private$credits)                   }                 ),                 private = list(                   password = NULL,                   credits  = NULL                 )               )  # \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 user_1 &lt;- User$new('Alex', 'secretpwd')  # \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e user_1$get_credits()<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">100<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 <code>credits<\/code> \u0447\u0435\u0440\u0435\u0437 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434. \u041d\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0443, \u0442\u043e \u0443 \u043d\u0430\u0441 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"r\"># \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u043e\u043c\u0443 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0443 \u0432\u043d\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 user_1$credits<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">NULL<\/code><\/pre>\n<p>  <\/p>\n<h1 id=\"aktivnye-metody\">\u0410\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b<\/h1>\n<p>  <\/p>\n<p>\u0410\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u043a\u0430\u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u043d\u043e \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043a \u043d\u0438\u043c \u043e\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u0437\u0430\u0434\u0430\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043a \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u0443 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u044d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b, \u0438\u043b\u0438 \u0432\u044b\u0431\u043e\u0440\u0430 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0432\u0435\u043a\u0442\u043e\u0440\u0430.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u043a\u043e\u0442\u0443, \u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>dictionary<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0432\u0435\u043a\u0442\u043e\u0440 \u0437\u0432\u0443\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u043a\u043e\u0442. \u0418 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>$say()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u043e\u0434\u043d\u0443 \u0438\u0437 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u0444\u0440\u0430\u0437.<\/p>\n<p>  <\/p>\n<pre><code class=\"r\">library(R6)  # \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043b\u0430\u0441\u0441 Cat Cat &lt;- R6Class(classname = &quot;Cat&quot;,                public = list(                  name  = NA,                  breed = NA,                  dictionary = NA,                   initialize = function(name, breed, dictionary) {                    self$name         &lt;- name                    self$breed        &lt;- breed                    self$dictionary   &lt;- dictionary                  }                ),                active = list(                  say = function(value) {                    if (missing(value)) {                       return(paste0(self$name, ' say ', sample(self$dictionary, size = 1)))                     } else {                       self$dictionary &lt;- value                     }                  }               )            )  # \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 cat &lt;- Cat$new('Tom',                 'Persian',                 c('meow', 'mrrr', 'frrr'))  # \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 cat$say <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">[1] &quot;Tom say meow&quot;<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435 \u043a \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u043c\u044b \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a\u0430\u043a \u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c, \u0442.\u0435. \u0431\u0435\u0437 \u0441\u043a\u043e\u0431\u043e\u043a \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>say<\/code>. <\/p>\n<p>  <\/p>\n<p>\u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 <code>if (missing(value))<\/code>, \u0442.\u0435. \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0435\u0441\u043b\u0438 \u0438\u0434\u0451\u0442 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u0443, \u0442\u043e \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u0443\u044e \u0444\u0440\u0430\u0437\u0443 \u0438\u0437 <code>self$dictionary<\/code>. \u0415\u0441\u043b\u0438 \u0432 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0443\u0441\u043b\u043e\u0432\u0438\u0435 <code>else<\/code>, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 <code>self$dictionary<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"r\"># \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e cat$say &lt;- c('grrr', 'waw', 'chfw') # \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 cat$say<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">&quot;Tom say grrr&quot;<\/code><\/pre>\n<p>  <\/p>\n<h1 id=\"finalizator-klassa\">\u0424\u0438\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u043a\u043b\u0430\u0441\u0441\u0430<\/h1>\n<p>  <\/p>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>$finalize<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u0440\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 R \u0441\u0435\u0441\u0441\u0438\u0438. <\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0432 \u0442\u0435\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u0448 \u043a\u043b\u0430\u0441\u0441 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0444\u0430\u0439\u043b\u0430\u043c\u0438 \u0438\u043b\u0438 \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u043e\u0433\u0434\u0430 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0444\u0438\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0431\u044b \u0431\u044b\u0442\u044c \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u043c, \u0447\u0442\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u0444\u0430\u0439\u043b\u043e\u043c \u0438\u043b\u0438 \u0431\u0430\u0437\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u043e\u0440\u0432\u0430\u043d\u043e.<\/p>\n<p>  <\/p>\n<pre><code class=\"r\">TemporaryFile &lt;- R6Class(&quot;TemporaryFile&quot;, list(   path = NULL,   initialize = function() {     self$path &lt;- tempfile()   },   finalize = function() {     message(&quot;Cleaning up &quot;, self$path)     unlink(self$path)   } ))<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0432\u0437\u044f\u0442 \u0438\u0437 \u043a\u043d\u0438\u0433\u0438 <a href=\"https:\/\/adv-r.hadley.nz\/r6.html#finalizer\" rel=\"nofollow\">Advanced R<\/a>, \u0430\u0432\u0442\u043e\u0440 Hadley Wickham<\/p><\/blockquote>\n<p>  <\/p>\n<h1 id=\"dobavlenie-r6-klassov-v-paket\">\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 R6 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0432 \u043f\u0430\u043a\u0435\u0442<\/h1>\n<p>  <\/p>\n<p>\u0415\u0449\u0451 \u043e\u0434\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0438\u0435 R6 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043e\u0442 S3 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u0430\u043c \u043d\u0435 \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432\u0430\u0448\u0438 R6 \u043a\u043b\u0430\u0441\u0441\u044b \u0432 \u0444\u0430\u043b\u0435 NAMESPACE. \u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043f\u0430\u043a\u0435\u0442 R6 \u0432 \u043f\u043e\u043b\u0435 <code>Imports<\/code> \u0444\u0430\u0439\u043b\u0430 DESCRIPTION.<\/p>\n<p>  <\/p>\n<h1 id=\"poleznye-ssylki\">\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438<\/h1>\n<p>  <\/p>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u043e\u043c \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u0430\u043d\u0433\u043b\u043e\u044f\u0437\u044b\u0447\u043d\u043e\u0439 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438, \u043d\u043e \u043f\u0440\u0438 \u0435\u0451 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430\u043c\u0438:<\/p>\n<p>  <\/p>\n<ol>\n<li><a href=\"https:\/\/adv-r.hadley.nz\/r6.html\" rel=\"nofollow\">Advanced R, Hadley Wickham<\/a><\/li>\n<li><a href=\"https:\/\/r6.r-lib.org\/\" rel=\"nofollow\">R6: Encapsulated object-oriented programming for R, Winston Chang<\/a><\/li>\n<\/ol>\n<p>  <\/p>\n<h1 id=\"zaklyuchenie\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h1>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u044b \u0443\u0431\u0435\u0434\u0438\u043b\u0438\u0441\u044c R6 \u043a\u043b\u0430\u0441\u0441\u044b \u044d\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u044f\u0437\u044b\u043a\u0435 R.<\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 R \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0440\u0435\u0434\u043a\u043e, \u0442.\u043a. \u0440\u043e\u0434\u043d\u043e\u0439, \u0438 \u043e\u0431\u0449\u0435\u043f\u0440\u0438\u043d\u044f\u0442\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u041e\u041e\u041f \u0432 R \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0441\u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f <a href=\"https:\/\/habr.com\/ru\/post\/453964\/\">S3 \u043a\u043b\u0430\u0441\u0441\u044b<\/a>.<\/p>\n<\/div>\n<p> \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\/post\/521310\/\"> https:\/\/habr.com\/ru\/post\/521310\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<p>\u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 <a href=\"https:\/\/habr.com\/ru\/post\/453964\/\">\u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438<\/a> \u043c\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438 S3 \u043a\u043b\u0430\u0441\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c\u0438 \u0432 \u044f\u0437\u044b\u043a\u0435 R. <\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c\u0441\u044f \u0441 R6 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0451\u043d\u043d\u044b\u0435 \u043a \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e.<\/p>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/bo\/ct\/yv\/boctyvkro_bo7tyi4n3ckrka4eu.png\" width=\"80%\"><\/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-312864","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/312864","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=312864"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/312864\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=312864"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=312864"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=312864"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}