Meta tags:
description= In software engineering, the delegation pattern is an object-oriented design pattern that allows object composition to achieve the same code reuse as an inheritance.;
author= Pankaj Singh;
Headings (most frequently used words):
pattern, using, lambda, delegating, decorator, java, features, and, improvement, strategy, design, patterns, share, this, related, posts, about, the, author, pankaj, singh,
Text of the page (most frequently used words):
spring (34), interview (20), tutorial (18), the (18), java (17), and (11), supplier (9), microservices (8), int (8), boot (7), design (7), using (7), lambda (7), pattern (7), share (7), new (7), public (7), lazy (7), jax (6), core (6), opens (6), window (6), calculate (6), temp (6), delegation (6), system (6), out (6), println (6), hibernate (5), object (5), delegating (5), web (4), security (4), mvc (4), aop (4), cloud (4), soap (4), patterns (4), let (4), run (4), code (4), called (4), private (4), static (4), path (4), instance (4), can (4), maven (3), batch (3), with (3), react (3), this (3), now (3), test (3), that (3), method (3), package (3), class (3), return (3), get (3), execution (3), privacy (2), policy (2), who (2), training (2), service (2), linux (2), git (2), thymeleaf (2), mongo (2), ant (2), gradle (2), build (2), tools (2), ajax (2), hadoop (2), mail (2), api (2), jdbc (2), jstl (2), jsp (2), servlet (2), j2ee (2), struts (2), computing (2), wsdl (2), rest (2), questions (2), services (2), tutorials (2), search (2), hateoas (2), mobile (2), certification (2), dinesh (2), monitoring (2), testing (2), learn (2), solve (2), common (2), problems (2), pinterest (2), telegram (2), whatsapp (2), linkedin (2), facebook (2), function (2), only (2), once (2), you (2), lazytest (2), calculte (2), void (2), main (2), string (2), args (2), integer (2), else (2), same (2), null (2), used (2), delegate (2), keyword (2), achieve (2), example (2), copyright, 2026, hands, performance, engineer, guide, continuous, full, stack, development, designing, applications, native, application, architecture, various, use, them, best, practices, specialties, technologies, jpa, apache, spark, kafka, pankaj, singh, about, author, strategy, features, improvement, decorator, related, posts, next, previous, change, then, because, assessed, within, which, fine, value, right, notice, not, being, final, import, util, calls, when, required, unfortunately, doesn, support, consider, other, languages, like, deferred, needed, for, scala, observe, its, output, never, demonstrate, necessity, look, software, engineering, oriented, allows, composition, reuse, inheritance, handles, request, second, helper, but, original, context, comments, october, 2022, home,
Text of the page (random words):
delegating pattern using lambda dinesh on java core java core java java 8 certification interview q a spring boot spring spring core spring aop spring mvc spring security microservices spring 4 spring 5 spring batch spring mobile spring hateoas hibernate hibernate search tutorials design patterns web services ws interview questions jax ws soap jax rs rest wsdl soap cloud computing struts 2 tutorial j2ee tutorial servlet tutorial jsp tutorial jstl tutorial jdbc tutorial jax b tutorial java mail api hadoop tutorial ajax tutorial build tools maven gradle ant mongo db thymeleaf git linux interview q a spring interview aop interview mvc interview spring boot interview microservices interview spring security interview web service interview training who i am privacy policy home java java 8 delegating pattern using lambda october 12 2022 no comments delegating pattern using lambda delegating pattern in software engineering the delegation pattern is an object oriented design pattern that allows object composition to achieve the same code reuse as an inheritance in delegation an object handles a request by delegating to a second object a delegate is a helper object but with the original context to demonstrate the necessity of delegation of execution let s look at an example package delegation public class lazytest private static int calculate int x system out println called return x 2 public static void main string args int x 5 int temp calculate 4 if x 5 temp 4 system out println path 1 else system out println path 2 if we run the code we can observe that the method calculate is only called once and its output is never used if we consider other languages like scala the execution can be deferred as needed by using the lazy keyword for example lazy int temp calculate 4 unfortunately java doesn t support the lazy keyword we can achieve this by using lambda lambda can be used to delegate method calls when execution is required let us design it package delegation import java util function supplier public class lazy t private t instance private supplier t supplier public lazy supplier t supplier this supplier supplier public t get if instance null instance supplier get supplier null return instance now let us test the same package delegation public class lazytest private static int calculte int x system out println called return x 2 public static void main string args int x 5 final lazy integer temp new lazy integer calculte 4 if x 5 temp get 4 system out println path 1 else system out println path 2 test 1 if you run the code right now you ll notice that the method calculate is not being called test 2 change the value of x to 15 and then run the code the function calculate is now only run once because the temp is assessed within it which is fine previous next share this share on facebook opens in new window facebook share on x opens in new window x share on linkedin opens in new window linkedin share on whatsapp opens in new window whatsapp share on telegram opens in new window telegram share on pinterest opens in new window pinterest java 8 related posts decorator pattern using lambda java 8 features and improvement strategy design patterns using lambda about the author pankaj singh specialties java technologies spring microservices hibernate jpa apache spark spring batch react js maven and kafka learn various design patterns and best practices and use them to solve common design problems learn spring boot 2 0 and spring cloud application microservices architecture to solve common cloud native problems designing applications with spring boot 2 2 and react js let us full stack development with spring boot and react js hands on microservices monitoring and testing a performance engineer s guide to the continuous testing and monitoring of microservices dinesh on java copyright 2026 core java core java java 8 certification interview q a spring boot spring spring core spring aop spring mvc spring security microservices spring 4 spring 5 spring batch spring mobile spring hateoas hibernate hibernate search tutorials design patterns web services ws interview questions jax ws soap jax rs rest wsdl soap cloud computing struts 2 tutorial j2ee tutorial servlet tutorial jsp tutorial jstl tutorial jdbc tutorial jax b tutorial java mail api hadoop tutorial ajax tutorial build tools maven gradle ant mongo db thymeleaf git linux interview q a spring interview aop interview mvc interview spring boot interview microservices interview spring security interview web service interview training who i am privacy policy
|