<p>Context object Design Pattern is one of the J2EE design patterns used to store references and pointers to configuration information and services needed by other objects. It allows different objects to interact with each other without every object needing to maintain all the information.</p>
<h2><strong>Context Object Design Pattern</strong></h2>
<p>The structure of the context object is such that it has a client, initial context, service locator, and service factory and business service. Each of the components has different tasks to perform and different responsibilities to cater. A client is an object which requires access to the business objects. It is basically, a client of the service locator. The service locator provides an interface to the clients. The clients can reuse the service locator. In the lookup and creation process, the initial context is the starting point. Service providers are responsible for providing the context objects. This might vary depending on the type of business object that is provided by the lookup and creation service of the Service locator. A certain object is responsible for providing life cycle management for the business service objects, Service Factory represents this object. The business service is basically a task that is required to be carried out by the service that the client is pursuing to access.</p>
<div style="background-color: #f2f9fc; border-radius: 3px; border: 1px solid #c9e6f2; line-height: 1.45; padding: 16px 16px 16px 16px;">
<h2 dir="ltr">Spring 5 Design Pattern Book</h2>
<div dir="ltr" style="color: #20124d; font-family: 'calibri' , sans-serif; font-size: 13pt; text-align: justify;">You could purchase my <strong>Spring 5 book</strong> that is with title name &#8220;<strong>Spring 5 Design Patterns</strong>&#8220;. This book is available on the <a href="https://www.amazon.in/Spring-Design-Patterns-Dinesh-Rajput/dp/1788299450/ref=sr_1_1?ie=UTF8&;qid=1507925340&;sr=8-1&;keywords=spring+5+design+pattern" target="_blank" rel="noopener"><strong>Amazon</strong></a> and <a href="https://www.packtpub.com/application-development/spring-5-design-patterns" target="_blank" rel="noopener"><strong>Packt</strong></a> publisher website. Learn various <strong>design patterns</strong> and <strong>best practices</strong> in Spring 5 and use them to solve common design problems. You could use author discount to purchase this book by using code- &#8220;<strong>AUTHDIS40</strong>&#8220;.</div>
<div dir="ltr"></div>
<div dir="ltr"><a href="https://www.amazon.in/Spring-Design-Patterns-Dinesh-Rajput/dp/1788299450/ref=sr_1_1?s=books&#038;ie=UTF8&#038;qid=1512607966&#038;sr=1-1&#038;keywords=dinesh+rajput" target="_blank" rel="noopener"><img class="aligncenter wp-image-3053 size-medium" title="Spring-5-Design-Pattern" src="https://dineshonjava.com/wp-content/uploads/2013/03/Spring-5-design-pattern-243x300.jpg" width="243" height="300" /></a></div>
</div>
<p>Context object improve the maintainability and reusability of a program as with shared resources and reference points, all saved in context objects, we can easily decipher which part of the program can be reused for another application and what needs changing. It also makes testing a great deal easier as for every error we can refer to context object and it will point us in the right direction. Using context objects allows us to change interface without much trouble because the program is divided into small parts and we can make changes without it affecting the whole program and whatever it does affect can be reached and corrected quite easily.</p>
<div style="text-align: left;">
<blockquote>
<p><strong>also read:</strong></p>
<ul style="text-align: left;">
<li><a title="https://dineshonjava.com/intercepting-filter-design-pattern/" href="https://dineshonjava.com/intercepting-filter-design-pattern/">Intercepting Filter Pattern</a></li>
<li><a title="https://dineshonjava.com/front-controller-design-pattern/" href="https://dineshonjava.com/front-controller-design-pattern/">Front Controller Pattern</a></li>
<li><a title="https://dineshonjava.com/application-controller-design-pattern/" href="https://dineshonjava.com/application-controller-design-pattern/">Application Controller Pattern</a></li>
<li><a title="https://dineshonjava.com/view-helper-design-pattern/" href="https://dineshonjava.com/view-helper-design-pattern/">View Helper Pattern</a></li>
<li><a title="https://dineshonjava.com/composite-view-design-pattern/" href="https://dineshonjava.com/composite-view-design-pattern/">Composite View Pattern</a></li>
<li><a title="https://dineshonjava.com/dispatcher-view-design-pattern/" href="https://dineshonjava.com/dispatcher-view-design-pattern/">Dispatcher View Pattern</a></li>
<li><a title="https://dineshonjava.com/service-to-worker/" href="https://dineshonjava.com/service-to-worker/">Service to Worker Pattern</a></li>
</ul>
</blockquote>
</div>
<h2><strong>Class Diagram for Context Objects Pattern</strong></h2>
<p>Let&#8217;s see the following class diagram for context objects pattern.</p>
<h3><img class="aligncenter wp-image-3594 size-full" src="https://dineshonjava.com/wp-content/uploads/2017/12/Context-Object.gif" alt="Context Objects Design Pattern" width="426" height="209" /><br />
ContextFactory</h3>
<p>Client uses this factory to produce Context Object.</p>
<h3>Context Object</h3>
<p>It used by client to share resource in the program.</p>
<h2>Benefits for Context Objects</h2>
<ul>
<li>Improves reusability and maintainability</li>
<li>Improves testability</li>
</ul>
<h2><strong>For Example</strong></h2>
<p>There are following example for this pattern</p>
<ul>
<li>ApplicationContext in the Spring Framework</li>
<li>SecurityContext in the Security API</li>
<li>ServletContext in the Servlet API</li>
</ul>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/intercepting-filter-design-pattern/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/front-controller-design-pattern/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '3593'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…