J2EEOnline J2EEOnline

EJB Architecture  «Prev  Next»
Lesson 6EJB Reusable Components
ObjectiveIdentify when it is appropriate to use Reusable components

EJB Reusable Components

Describe a reusable component and identify when it is appropriate to employ one. There used to be alot of talk in the media about components and component architectures as being the current best practices in developing modern systems.
So what are components ?
How do components help us to develop flexible systems?


EJB are created to handle larger applications. There are a many aspects and technologies that make up EJB and some of these technologies seem like overkill when considering a small microservice. Those technologies have a higher return on the cost spent and this is a subjective opinion. When creating small microservices you realize how simple the architecture is and that the technologies used can be kept to a minimum.

Component definition

A component is a physical and replaceable part of a system that provides a service and conforms to, and provides a realization of, a set of interfaces.
This definition comes from UML Users Guide which is available from the Book Store . page.Note that the term realization is used in a similar manner as,
"I have realized my dream," which means you have turned your dream into something real or concrete. Thus, diagrammatically, we can represent a component as having two parts:
  1. One or more interfaces which collectively form the "interface"
  2. The concrete realization

Component definition consisting of 1) Remote Object 2) Message 3) Interface 4) Implementation

The parts are separate…

The two parts of a component are separate and can be considered, to a certain degree, independently.
The client is dependent on the interface, not the implementation. The interface provides a specific service through methods that take parameters and return values.
These methods are invoked by messages sent from a client. The implementation (a specific realization) is coupled to, but independent of, the interface.
Thus, as long as the realization[1] implements[2] the interface methods, it can achieve that functionality any way it needs to. Think of it like a starter motor for your car. When you need a new starter motor for your car, you can go to the dealer or you can go to one of many third-party suppliers and manufacturers that will sell you one that will work.

The point is that all starter motors for your particular car will work.
They support a common interface (mounting points, voltage, performance, etc.) and provide a similar service. You will choose the one you actually buy based on price, reputation, reliability, availability, convenience, etc.
The specific starter motor you buy is a "realization" of the interface designed into your car.
Imagine if you had to get a particular starter motor that had to be custom built for your car.
Or even one that was built into the engine and was not a separate component, and was only available from the dealer.
It would cost a fortune and you would be at the mercy of the supplier. To avoid this, we use replaceable components to build our applications, giving us low cost and flexibility.

Distributed Systems Basics

The link below contains more information regarding parts of a distributed object system.
Distributed Systems Basics
In the next lesson, you will be introduced to Object Monitors.

[1]Realization :The concrete implementation of one or more interfaces.
[2]Implement: An object that provides a realization of a particular interface is said to implement that interface.