{"id":6406,"date":"2012-08-25T00:18:31","date_gmt":"2012-08-24T18:48:31","guid":{"rendered":"https:\/\/2thenew.xyz\/blog\/?p=6406"},"modified":"2016-12-19T15:30:58","modified_gmt":"2016-12-19T10:00:58","slug":"what-is-delegate","status":"publish","type":"post","link":"https:\/\/2thenew.xyz\/blog\/what-is-delegate\/","title":{"rendered":"What is Delegate ??"},"content":{"rendered":"<p>Suppose a scenario, where User and Account classes are linked as below:<br \/>\n[groovy]<br \/>\nclass Account {<br \/>\n    String email<br \/>\n    String password<br \/>\n    \/\/ &#8230; other fields<br \/>\n}<\/p>\n<p>class User {<br \/>\n    Account account<br \/>\n    String name<br \/>\n    String address<br \/>\n    \/\/ &#8230; other fields<br \/>\n}<br \/>\n[\/groovy]<\/p>\n<p style=\"padding:10px\">\n<p>At the time of creating a new User, and accessing the user members, we write something of this sort:<br \/>\n[groovy]<br \/>\n\/\/ For initalizing the user class first we have to initializing Account class.<br \/>\nAccount account = new Account(email:&#8221;amit.kumar@gmail.com&#8221;, password:&#8221;intelligrape&#8221;)<br \/>\n\/\/ Now have to pass that account instance for initializing User class<br \/>\nUser user = new User(account:account, name:&#8221;Amit&#8221;, address:&#8221;Intelligrape City&#8221;)<\/p>\n<p>\/\/ For Accessing User&#8217;s Account information we have to use &#8220;user.account&#8221; as prefix<br \/>\nprintln user.account.email<br \/>\nprintln user.account.password<br \/>\n[\/groovy]<\/p>\n<p style=\"padding:10px\">\n<p>It can be clearly seen that we have to write &#8220;user.account&#8221; as a prefix for accessing user&#8217;s account information and have to initialize account info separately. If we use @Delegate annotation before account declaration as below:<br \/>\n[groovy]<br \/>\n @Delegate Account account = new Account()<br \/>\n[\/groovy]<\/p>\n<p style=\"padding:10px\">\n<p>Time is saved and groovy will manage account for user automatically. We do not need to care for initializing account information separately.<br \/>\n[groovy]<br \/>\n\/\/ Initializing account information with User class.<br \/>\nUser user = new User(email:&#8221;amit.kumar@gmail.com&#8221;, password:&#8221;intelligrape&#8221;, name:&#8221;Amit&#8221;, address:&#8221;Intelligrape City&#8221;)<br \/>\n\/\/ Accessing User Account info with &#8220;user&#8221; prefix only instead of &#8220;user.account&#8221; prefix<br \/>\nprintln user.email<br \/>\nprintln user.password<br \/>\n[\/groovy]<\/p>\n<p style=\"padding:10px\">\n<p><strong>Note:<\/strong> When you use <strong>@Delegate<\/strong> annotation, all the methods of delegated class(Account) are implement in current class(User), so we will be able to access those members with prefix (&#8220;user&#8221;) only.<\/p>\n<p>Amit Kumar<br \/>\n<a href=\"https:\/\/2thenew.xyz\/blog\/author\/amit.kumar\/\">amit.kumar@intelligrape.com<\/a><br \/>\nin.linkedin.com\/in\/amitkumar0110<br \/>\ntwitter.com\/amit_kumar0110<br \/>\n<strong><a href=\"https:\/\/2thenew.xyz\/blog\/author\/amit-kumar\/\">More Blogs by Me<\/a><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Suppose a scenario, where User and Account classes are linked as below: [groovy] class Account { String email String password \/\/ &#8230; other fields } class User { Account account String name String address \/\/ &#8230; other fields } [\/groovy] At the time of creating a new User, and accessing the user members, we write [&hellip;]<\/p>\n","protected":false},"author":52,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":1,"footnotes":""},"categories":[7],"tags":[885,9],"class_list":["post-6406","post","type-post","status-publish","format-standard","hentry","category-grails","tag-delegate","tag-groovy"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Suppose a scenario, where User and Account classes are linked as below: [groovy] class Account { String email String password \/\/ ... other fields } class User { Account account String name String address \/\/ ... other fields } [\/groovy] At the time of creating a new User, and accessing the user members, we write\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Amit Kumar\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/2thenew.xyz\/blog\/what-is-delegate\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"What is Delegate ?? | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"Suppose a scenario, where User and Account classes are linked as below: [groovy] class Account { String email String password \/\/ ... other fields } class User { Account account String name String address \/\/ ... other fields } [\/groovy] At the time of creating a new User, and accessing the user members, we write\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/2thenew.xyz\/blog\/what-is-delegate\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"What is Delegate ?? | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Suppose a scenario, where User and Account classes are linked as below: [groovy] class Account { String email String password \/\/ ... other fields } class User { Account account String name String address \/\/ ... other fields } [\/groovy] At the time of creating a new User, and accessing the user members, we write\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/what-is-delegate\\\/#article\",\"name\":\"What is Delegate ?? | TO THE NEW Blog\",\"headline\":\"What is Delegate ??\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/amit-kumar\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"datePublished\":\"2012-08-25T00:18:31+05:30\",\"dateModified\":\"2016-12-19T15:30:58+05:30\",\"inLanguage\":\"en-US\",\"commentCount\":1,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/what-is-delegate\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/what-is-delegate\\\/#webpage\"},\"articleSection\":\"Grails, delegate, Groovy\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/what-is-delegate\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"name\":\"Grails\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"position\":2,\"name\":\"Grails\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/what-is-delegate\\\/#listItem\",\"name\":\"What is Delegate ??\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/what-is-delegate\\\/#listItem\",\"position\":3,\"name\":\"What is Delegate ??\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"name\":\"Grails\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/amit-kumar\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/amit-kumar\\\/\",\"name\":\"Amit Kumar\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/what-is-delegate\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/859356966acd3c3879759369c7ac72cfb81228287bfc78e99c3080bee9b6b9ba?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Amit Kumar\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/what-is-delegate\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/what-is-delegate\\\/\",\"name\":\"What is Delegate ?? | TO THE NEW Blog\",\"description\":\"Suppose a scenario, where User and Account classes are linked as below: [groovy] class Account { String email String password \\\/\\\/ ... other fields } class User { Account account String name String address \\\/\\\/ ... other fields } [\\\/groovy] At the time of creating a new User, and accessing the user members, we write\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/what-is-delegate\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/amit-kumar\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/amit-kumar\\\/#author\"},\"datePublished\":\"2012-08-25T00:18:31+05:30\",\"dateModified\":\"2016-12-19T15:30:58+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"What is Delegate ?? | TO THE NEW Blog","description":"Suppose a scenario, where User and Account classes are linked as below: [groovy] class Account { String email String password \/\/ ... other fields } class User { Account account String name String address \/\/ ... other fields } [\/groovy] At the time of creating a new User, and accessing the user members, we write","canonical_url":"https:\/\/2thenew.xyz\/blog\/what-is-delegate\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/2thenew.xyz\/blog\/what-is-delegate\/#article","name":"What is Delegate ?? | TO THE NEW Blog","headline":"What is Delegate ??","author":{"@id":"https:\/\/2thenew.xyz\/blog\/author\/amit-kumar\/#author"},"publisher":{"@id":"https:\/\/2thenew.xyz\/blog\/#organization"},"datePublished":"2012-08-25T00:18:31+05:30","dateModified":"2016-12-19T15:30:58+05:30","inLanguage":"en-US","commentCount":1,"mainEntityOfPage":{"@id":"https:\/\/2thenew.xyz\/blog\/what-is-delegate\/#webpage"},"isPartOf":{"@id":"https:\/\/2thenew.xyz\/blog\/what-is-delegate\/#webpage"},"articleSection":"Grails, delegate, Groovy"},{"@type":"BreadcrumbList","@id":"https:\/\/2thenew.xyz\/blog\/what-is-delegate\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog#listItem","position":1,"name":"Home","item":"https:\/\/2thenew.xyz\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/category\/grails\/#listItem","name":"Grails"}},{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/category\/grails\/#listItem","position":2,"name":"Grails","item":"https:\/\/2thenew.xyz\/blog\/category\/grails\/","nextItem":{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/what-is-delegate\/#listItem","name":"What is Delegate ??"},"previousItem":{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/what-is-delegate\/#listItem","position":3,"name":"What is Delegate ??","previousItem":{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/category\/grails\/#listItem","name":"Grails"}}]},{"@type":"Organization","@id":"https:\/\/2thenew.xyz\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/2thenew.xyz\/blog\/"},{"@type":"Person","@id":"https:\/\/2thenew.xyz\/blog\/author\/amit-kumar\/#author","url":"https:\/\/2thenew.xyz\/blog\/author\/amit-kumar\/","name":"Amit Kumar","image":{"@type":"ImageObject","@id":"https:\/\/2thenew.xyz\/blog\/what-is-delegate\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/859356966acd3c3879759369c7ac72cfb81228287bfc78e99c3080bee9b6b9ba?s=96&d=mm&r=g","width":96,"height":96,"caption":"Amit Kumar"}},{"@type":"WebPage","@id":"https:\/\/2thenew.xyz\/blog\/what-is-delegate\/#webpage","url":"https:\/\/2thenew.xyz\/blog\/what-is-delegate\/","name":"What is Delegate ?? | TO THE NEW Blog","description":"Suppose a scenario, where User and Account classes are linked as below: [groovy] class Account { String email String password \/\/ ... other fields } class User { Account account String name String address \/\/ ... other fields } [\/groovy] At the time of creating a new User, and accessing the user members, we write","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/2thenew.xyz\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/2thenew.xyz\/blog\/what-is-delegate\/#breadcrumblist"},"author":{"@id":"https:\/\/2thenew.xyz\/blog\/author\/amit-kumar\/#author"},"creator":{"@id":"https:\/\/2thenew.xyz\/blog\/author\/amit-kumar\/#author"},"datePublished":"2012-08-25T00:18:31+05:30","dateModified":"2016-12-19T15:30:58+05:30"},{"@type":"WebSite","@id":"https:\/\/2thenew.xyz\/blog\/#website","url":"https:\/\/2thenew.xyz\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/2thenew.xyz\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"What is Delegate ?? | TO THE NEW Blog","og:description":"Suppose a scenario, where User and Account classes are linked as below: [groovy] class Account { String email String password \/\/ ... other fields } class User { Account account String name String address \/\/ ... other fields } [\/groovy] At the time of creating a new User, and accessing the user members, we write","og:url":"https:\/\/2thenew.xyz\/blog\/what-is-delegate\/","og:image":"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"What is Delegate ?? | TO THE NEW Blog","twitter:description":"Suppose a scenario, where User and Account classes are linked as below: [groovy] class Account { String email String password \/\/ ... other fields } class User { Account account String name String address \/\/ ... other fields } [\/groovy] At the time of creating a new User, and accessing the user members, we write","twitter:image":"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"6406","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2021-04-30 08:10:00","updated":"2024-02-29 10:55:24","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/2thenew.xyz\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/2thenew.xyz\/blog\/category\/grails\/\" title=\"Grails\">Grails<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tWhat is Delegate ??\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/2thenew.xyz\/blog"},{"label":"Grails","link":"https:\/\/2thenew.xyz\/blog\/category\/grails\/"},{"label":"What is Delegate ??","link":"https:\/\/2thenew.xyz\/blog\/what-is-delegate\/"}],"_links":{"self":[{"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/posts\/6406","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/users\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/comments?post=6406"}],"version-history":[{"count":0,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/posts\/6406\/revisions"}],"wp:attachment":[{"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/media?parent=6406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/categories?post=6406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/tags?post=6406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}