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.
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.
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.
also read:
Let’s see the following class diagram for context objects pattern.
Client uses this factory to produce Context Object.
It used by client to share resource in the program.
There are following example for this pattern
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…