Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Will this cause auto-failure?

 
Zee Ho
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sun provides me the interface as the following


Can I change it to


in this way, I can use only one interface to handle the local and
remote data object, else I should create one additional, will this cause the auto failure? I am afraid about it.

And also, I write the remote data object with the Adapter design pattern, this way belongs to "Modification" or "Extension"? becuse my english is quite poor, I can not distinguish those two word under this scenario
[ April 18, 2005: Message edited by: Zee Ho ]
 
Frans Janssen
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Zee,

That would surely lead you to autofailure, because you would also need to add throws RemoteException to all methods in the interface. And that would certainly not be allowed.

The Adapter pattern is indeed the way to solve this, but I am afraid I do not understand what your question about this is.

Frans.
[ April 18, 2005: Message edited by: Frans Janssen ]
 
Zee Ho
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Base on your suggestion, I plan to do the following changes :


in the first interface I throw both the RemoteException and Exception expected in the spec which sun offer me.

in the second interface only throw the Exception required by Sun

in the third interface do same as the first one.

but in this way I still change a little on the interface which sun provide me, I should rewrite it as


and wouldn't this lead the auto-failure? maybe there's some other great way to do it, but I can not figure it out. pls help me on this, thx in advance.
 
Frans Janssen
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm,

I really don't dare to say if that will get you into trouble. Technically it seems correct, but I doubt that adding the "extends" to the interface given by Sun is allowed.

I would not take the risk of an auto-failure and play safe and go for an Adapter pattern.

The Adapter class would implement your DBSuperInterface interface and forward all calls to its methods to the class that implements DBAccess. Then DBAccess does not need to implement DBSuperInterface.

Hope this helps,

Frans.
 
Zee Ho
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
then I want to know do you implement something like the DAOFactory to return the remote or local data object? since you don't let those two implement the same interface then how you integrate the return type of the method like getDataObject(I can return it as the DBSuperInterface in this way)? but how to do it in your way? return Object instead? then cast it become a trouble. maybe I miss something.
 
Zee Ho
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you offer me a brief sample code about ur way.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but how to do it in your way? return Object instead? then cast it become a trouble.

If you wish, you could use Tiger's Generics features to avoid the casting problem.

Nick
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Zee Ho:
can you offer me a brief sample code about ur way.


Search this forum for the adapter pattern, I'm certain you'll find your answer
 
Frans Janssen
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zee,

My approach was to have one Adapter interface, which extends Remote. I have two Adapter classes that implement this interface; LocalAdapter and RemoteAdapter. They both do nothing more than forward all their calls to a Data instance, e.g. like this:

RemoteAdapter is a Remote object (extends UnicastRemoteObject) and LocalAdapter is not (it never will throw RemoteException).

I have a Factory class that creates RemoteAdapters for networked mode and LocalAdapters for standalone mode. The business tier talks to an instance of Adapter, but does not need to know which subclass.

HTH,

Frans.
 
Zee Ho
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. Maybe I know what u mean now, I draw a diagram for what you mentioned.


so In your DAOFactory, you just return the Adapter interface. In this way, we have two interace, DBAccess and Adapter(which is quite similar with DBAccess, but it throws RemoteException and Sun's Exception). is it right?
[ April 19, 2005: Message edited by: Zee Ho ]
 
Frans Janssen
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Zee Ho:
[QB]so In your DAOFactory, you just return the Adapter interface. In this way, we have two interace, DBAccess and Adapter(which is quite similar with DBAccess, but it throws RemoteException and Sun's Exception). is it right?
QB]


Exactly right!

Frans.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic