Originally posted by Ryan Tang:
I have the following design for my local/remote database, but it seems complicated...
1. Class Data implements interface DB as required by Sun![]()
2. Interface Database that have all methods in DB and getMetaData(), all of them throws RemoteException![]()
3. Interface LocalDatabase extends Database which overrides all methods in Database so that no RemoteException is thrown![]()
4. Interface RemoteDatabase extends Database & Remote![]()
5. Class LocalDatabaseImpl extends Data implements LocalDatabase![]()
6. Class RemoteDatabaseImpl extends UnicastRemoteObject implements RemoteDatabase![]()
7. Internally, RemoteDatabaseImpl delegates all requests to a LocalDatabaseImpl instance![]()
8. Class RemoteDatabaseFactoryImpl, a factory binded to RMI registry for the RemoteDatabaseImpl![]()
9. Adaptor Services at client side which has a reference to Database, either a local or remote one, to provide business methods![]()
10. Client interacts with Services and be unaware of the nature of the database![]()
All exceptions(remote or not) are caught in Services, and only the ServiceException is thrown from Services.![]()
The same Services class is used for local/network mode, a violation of the requirement? No, it's![]()
So many similar interfaces, which are confusing for a "junior programmer"...so marks deducted...? Yes, keep theones and get rid of the
ones.
Regards, George
SCJP, SCJD, SCWCD, SCBCD
I question the need for 3, 5, and 7. Possibly I just don't understand what value they add, but possibly they don't really add any value.
I think 8 and 9 can probably be combined.
10 is a laudable goal and I think your design gets you there
1. Restricted by the requirement, I must have the interface Database.
So Database represents your common database interface (for both common and remote access).
2. Much of the Database implementation is done by Data, but unfortunately, not all...
But Data could implement everything in Database, couldn't it? Not doing so is a design decision, but it results in your design having another interface that wouldn't be needed if Data fully implemented everything in Database. You said your design seemed a little complicated and I'm just saying that this seems like an opportunity for possibly getting rid of an (extra) interface (that may not be needed).
3. So I must have a class DatabaseImpl which extends Data and provide the additional implementation.
It's one way of doing it but as stated above it comes at the cost of having an additional interface and implementation. Maybe you think it makes Data easier to understand, and if so, then you should keep it.
4. This DatabaseImpl should be used in remote mode, so I have my so-called delegation in point 7.
I didn't mean to say anything against delegation, I really meant to say you could delegate to Data (if it implemented everything itself) rather than to DatabaseImpl.
5. So in remote mode, Services has reference to the RemoteDatabaseImpl; in local mode, the DatabaseImpl.
Instead of DatabaseImpl it could be Data, couldn't it?
6. But DatabaseImpl, used locally, has an interface that throws RemoteException(violation of the requirement?).
Maybe Database could throw IOException, then it could truly function as the base interface for local and remote database access. It would be the direct interface for the local database access. And a remote database access interface could extend Database and Remote.
7. So I add the LocalDatabase, LocalDatabaseImpl...
There's nothing wrong with having LocalDatabase and LocalDatabaseImpl, but if you're telling me you're concerned about the complexity of your design I'm saying that these seem to me to be candidates for elimination. If you are comfortable with the rationales for having LocalDatabase and LocalDatabaseImpl, then that's a defensible position, and you should feel better about the complexity. In that case, the design wounldn't be too complex, it would be just complex enough.
I have the following design for my local/remote database, but it seems complicated...
1. Class Data implements interface DB as required by Sun
Agree.
2. Interface Database that have all methods in DB and getMetaData(), all of them throws RemoteException
Maybe it could throw IOException if you want it serve as the common interface for both local and remote database access.
3. Interface LocalDatabase extends Database which overrides all methods in Database so that no RemoteException is thrown
If you accept the suggestion in 3, then perhaps this is no longer a problem.
4. Interface RemoteDatabase extends Database & Remote
Agree.
5. Class LocalDatabaseImpl extends Data implements LocalDatabase
Only necessary if your Data class doesn't already do it.
6. Class RemoteDatabaseImpl extends UnicastRemoteObject implements RemoteDatabase
Agree.
7. Internally, RemoteDatabaseImpl delegates all requests to a LocalDatabaseImpl instance
It could delegate to Data.
8. Class RemoteDatabaseFactoryImpl, a factory binded to RMI registry for the RemoteDatabaseImpl
I may have misunderstood what you were trying to do here. It may not be as closely related to 9 as I thought. If you say that RemoteDatabaseFactoryImpl gives you an object that implements RemoteDatabase (which itself implements Database), then I have no objection.
9. Adaptor Services at client side which has a reference to Database, either a local or remote one, to provide business methods
Is this the Controller from the MVC pattern? If so, again no objection.
10. Client interacts with Services and be unaware of the nature of the database
Still sounds good.[b]
Regards, George
SCJP, SCJD, SCWCD, SCBCD
Originally posted by Trym Moeller:
Ryan Tang: I have implemented the RemoteDatabase as you have delegating to the LocalDatabase.
George Marinkovich: And I don't see, what is wrong with this approach, can you please elaborate on this.[ January 19, 2004: Message edited by: Trym Moeller ]
Regards, George
SCJP, SCJD, SCWCD, SCBCD
But Data could implement everything in Database, couldn't it?
Regards, George
SCJP, SCJD, SCWCD, SCBCD
Regards, George
SCJP, SCJD, SCWCD, SCBCD
Regards, George
SCJP, SCJD, SCWCD, SCBCD
Consider Paul's rocket mass heater. |