Académique Documents
Professionnel Documents
Culture Documents
Java
Before
Because the interface between Line and Rectangle objects is incompatible, the user has to
recover the type of each shape and manually supply the correct arguments.
class LegacyLine {
public void draw(int x1, int y1, int x2, int y2) {
System.out.println("line from (" + x1 + ',' + y1 + ") to (" + x2 + ','
+ y2 + ')');
}
}
class LegacyRectangle {
public void draw(int x, int y, int w, int h) {
System.out.println("rectangle at (" + x + ',' + y + ") with width " + w
+ " and height " + h);
}
}
The Adapter’s “extra level of indirection” takes care of mapping a user-friendly common
interface to legacy-specific peculiar interfaces.
class LegacyLine
{
public void draw(int x1, int y1, int x2, int y2)
{
System.out.println("line from (" + x1 + ',' + y1 + ") to (" + x2 + ','
+ y2 + ')');
}
}
class LegacyRectangle
{
public void draw(int x, int y, int w, int h)
{
System.out.println("rectangle at (" + x + ',' + y + ") with width " + w
+ " and height " + h);
}
}
interface Shape
{
void draw(int x1, int y1, int x2, int y2);
}
What is RMI?
Answer
Remote Method Invocation. It is an approach where a method on a remote machine invokes another
method on another machine to perform some computation and return the result to the calling method.
What is RMI?
To interact with the methods of objects in other / remote machines using JVM, RMI is used. This
process allows the information exchanging using multiple JVMs. It provides the location
transparency by giving the sense that the methods accessing locally.
Advantages of RMI:
Simple and clean to implement that leads to more robust, maintainable and flexible applications
Distributed systems creations are allowed while decoupling the client and server objects
simultaneously
It is possible to create zero-install client for the users.
No client installation is needed except java capable browsers
At the time of changing the database, only the server objects are to be recompiled but not the
server interface and the client remain the same.
Disadvantages of RMI:
RMI is based on client-server architecture model. The stub plays the role of a proxy server for
the remote objects. The skeleton lives in the same JVM as the remote object and communication
will be handled with the stub. The remote references are managed by the registry. The binding of
server with reference to itself will be on the registry. The clients communicate with a registry
which in turn obtains a remote reference to the server. This could be a remote host. The remote
reference could be obtained by the client from the registry in order to invoke the methods from
the remote object.
RMI and CORBA – one is not “better” than other. The comparisons between these two
technologies reveal the strengths and weaknesses. The applicability of these two technologies is
purely depends on the application’s demand, feasibility, performance.
The selection of RMI or CORBA depends on the following advantages of RMI and CORBA.
RMI Advantages:
RMI disadvantages:
CORBA advantages:
CORBA disadvantages:
Interface Definition Language mapping needs writing for one language may not support the
another language.
New changes in the existing system / code may not integrate with the IDL language tools.
Data transfer or objects is not supported by CORBA
If CORBA specifications fails for adoption by the industry, then it become legacy system.