> Amarnath P wrote:
>
> hi andrea,
>
> can u explain more clearly about the lack of OO principles, that
> u have mentioned below ?????
The basic principle of having a factory class that creates unknown
instance objects with a common base class. For example, I have a factory
public class ShapeFactory {
public Shape createShape(String name);
}
and
public interface Shape {
}
And a bunch of shape objects:
public class Cone extends Shape {}
public class Box extends Shape {}
public class Sphere extends Shape {}
I cannot create an EJB home interface that generates me a different
instance object depending on the parameter that I pass to the
ejbCreate() method. That is, the following home interface is illegal:
public interface ShapeHome extends EJBHome {
public Shape create(String name);
}
because it is required to return an instance of the Shape class eg
public class ShapeEJB implements EntityBean {}
These classes cannot be cast to a narrower definition to get something
more useful.
EJBs do allow something similar, but not quite as flexible. What you
would have to do is create a bunch of home interfaces that were similar,
but registered under different JDNI context names. This would given you
almost a factory, but instead of using a method that takes a string name
in the create, you would have to look up the home interface for a
dynamically created context name. eg
public class MyShapeUtils {
public static Shape createShape(string name) {
String ctx_name = "ejb/shapes/" + name;
InitialContext ctx = new InitialContext();
ShapeHome home = (ShapeHome)ctx.lookup(ctx_name);
Shape shape = home.create();
return shape;
}
}
--
Justin Couch http://www.vlc.com.au/~justin/
Freelance Java Consultant http://www.yumetech.com/
Author, Java 3D FAQ Maintainer http://www.j3d.org/
-------------------------------------------------------------------
"Humanism is dead. Animals think, feel; so do machines now.
Neither man nor woman is the measure of all things. Every organism
processes data according to its domain, its environment; you, with
all your brains, would be useless in a mouse's universe..."
- Greg Bear, Slant
-------------------------------------------------------------------
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".