wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes How to design the interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "How to design the interface" Watch "How to design the interface" New topic
Author

How to design the interface

Jeff Song
Greenhorn

Joined: Nov 05, 2002
Posts: 27
I read most of the design choose of SCJD in the forum. Most of high scorer use only one interface as the remote interface. And in both local mode and network mode,there is a DataClient and a DataServer which implements this interface. But I don't know which method should be declared in this interface.
In my original design, I declared some method like book(),getAllFlightInfo(),getFieldName()..5 methods. It it enought for use in network mode. My archtecture is UI-DataClient-interface-DataServer-BusinesslogicrsBean-Data-db.db.
But in the local mode, instruction said I must implement all the public method of Data.class, with origianl design,i.e. My DataClient only implement the method getAllFlightInformation(), within the class,I new a Data and manupulate the data instance to get the information. It is no need for me to implement the same methods(such as getRecordCount()) in the Data class. But the guide say I should do it. But I don't know why. Maybe my design is wrong?
Who can tell me which is the right design. If the Data Client should implement all the public method of Data, should Data server also implement the methods?
Local Mode: UI-Client-Data-db.db
Pls help me!!!
Mag Hoehme
Ranch Hand

Joined: Apr 07, 2002
Posts: 194
Hi Jeff,
running the program in local mode and in remote mode should be the same. Therefore I think the interface should be the same for both modes.
You can have several objects (e.g. a local-mode object and a remote-mode object) which implement the same interface. And a factory creates the one you need at runtime.


Mag
Jeff Song
Greenhorn

Joined: Nov 05, 2002
Posts: 27
which method should I declare in this interface? is it necessarily to declare all public method of Data class in the interface?
If not, how to implements all the public method of Data class,like below?
public int getRecordCount() {
return data.getRecordCount();
}
confusing....
Mag Hoehme
Ranch Hand

Joined: Apr 07, 2002
Posts: 194
Hi Jeff,
check your instructions: the "Data client" must have the same public interface as the Data.class.
So I took the following approach: I created an interface which had exactly the same methods as the Data.class. Then I extended this interface with business methods so that it could act as a facade.
If not, how to implements all the public method of Data class,like below?
public int getRecordCount() {
return data.getRecordCount();
}

This pattern is called "delegation": my client connected to the facade, and the facade delegated the calls to the Data.class.
Hope this helps.
Jeff Song
Greenhorn

Joined: Nov 05, 2002
Posts: 27
Dear Mag!
Thanks very much for ur help! I have wondering this matter for serveral days. It confused me so much. The pattern you said is delegation can be implement by the code I wrote allow?
Now I do the assignment in this way:
1.create a interface including all the public method of Data class.
2.create a DataClient to implement the interface and delegate the public method to Data instance.
3.put the business logical in DataClient and the business method invokes the method of DataClient.
4.create a DataServer and implement the interface and delegate the public method to remote Data instance.
5.Bind the DataServer to registry
Is my design right?? It is the result after checking many post of java Ranch. But I don't know it is right.Can u comment for me?
BTW,the design use factory pattern, Delegation patter and MVC pattern,does any other pattern are used?
Mag Hoehme
Ranch Hand

Joined: Apr 07, 2002
Posts: 194
Hi Jeff,
that looks fine to me. But I wouldn't make the Data.class the remote server.
If Data.class is your remote server, you put database logic (Data.class) and server logic (RMI) into one class.
I had a separate "connection server", which created a new facade object (or, as you call it, DataClient) per connection, and this facade delegated everything to the single instance of the Data.class. The advantage of this design is that all synchronization is "local" to the server, and thus much faster.
In addition, when my client ran in local mode, it simply instantiated the facade object. In this way my facade was used in either mode.
Hope this helps.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to design the interface