• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to design the interface

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!!
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jeff Song
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Did you ever grow anything in the garden of your mind? - Fred Rogers. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic