The inheritance-based approach to skeletons suffers from several drawbacks: It is conceptually unappealing, it may not work with already existing implementation classes, and it uses up Java's single inheritance for the class.
The delegation-based approach is usually the preferred alternative.
TIE
The TIE class (so called because it ties together an implementation class and the skeleton) generated for an IDL interface is a subclass of the inheritance-based skeleton.
The TIE class has a constructor that takes an instance of the corresponding operations interface. The TIE class delegates all the operations methods to the given operations instance.
Thus, to use the delegation-based (TIE) approach to write and use implementation objects, you:
Write an implementation class that implements the operations interface.
Use the implementation by passing an instance of it to the TIE class constructor to instantiate a TIE skeleton.
Example
The TIE generated for the Weather Service example would look like the following:
package weather;
/** stream-based skeleton class */
import org.omg.PortableServer.POA;
public class POA_WeatherService_tie extends POA_WeatherService{
private WeatherServiceOperations _delegate;
public POA_WeatherService_tie(WeatherServiceOperations delegate){
_delegate = delegate;
}
public java.lang.String getReport(java.lang.String city){
return _delegate.getReport(city);
}
// More generated code ...
}
Notice how the getReport() method delegates to the operations instance. We can write an implementation class to be used with this, as follows:
package weather;
//Implementation to be used with TIE class
public class WeatherServiceOperationsImpl
implements WeatherServiceOperations
{
public java.lang.String getReport(java.lang.
String city)
{
return "Sunny with a chance of objects";
}
}
To use this implementation class, the TIE will be instantiated with an instance of the implementation class:
POA_WeatherService_tie weatherTIE =
new POA_WeatherService_tie new WeatherServiceOperationsImpl());
The TIE approach is clearly a bit more involved than the inheritance approach. It has many benefits, however,
including cleaner structure and the ability to work with existing implementation classes that are already part of an inheritance hierarchy.
In the next lesson, you will learn about writing the basic server mainline that creates and manages the implementation objects and makes them available to clients.