• 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

DB Interface (URLyBird 1.1.2)

 
Ranch Hand
Posts: 71
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I got URLyBird 1.1.2 as my SCJD assignment several days ago. I've read through the instructions. According to the instruction, a class with the specified name must implement this the given interface.

Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface...



If I create additional methods which are not specified in the interface, will it result in automatic failure?

I would like to make the Data class as a Singleton. But the Data class is not a facade to the data layer. There would be another class as a facade but this class would not be a Singleton. Any comments and suggestions are greatly appreciated.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Allan,

Where are you going to add these additional methods?

So you will have your Data class (implementing Sun's interface) and then you will have another class in front of it which acts as a facade. So this other class will call some methods from the Data class and also will call some methods of another class. What will be the purpose of this other class that will be called by your facade?

Kind regards,
Roel
 
Allan Cheong
Ranch Hand
Posts: 71
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Roel,

Thanks for the reply.

I would like to add the additional methods in Data class.

I'll put it this way. Data class is Sun's interface. Facade has a Data class. Facade class methods accepts value object instead of array objects (unlike Sun's interface). The value object in this case I will create something like Room, which stores owner, rate, location and etc. Example of findRoom() method in Facade class:


Data.find(String[]) method are required by Sun's interface. This design the first thing that comes on top of my mind. Please comment.

Another question here. Should there be a class created as a Monitor to the threads? The instructions did not mention about what the server can do other than accepting socket connections to access the db file. Hmm..
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Allan,

Just adding the methods to your Data class will be considered a bad design, because you should try as much as possible to program against interfaces, so your code becomes implementation-independent.
If you develop your code only using references of type Data (instead of DBMain) and you add specific methods to your Data class, your code will work perfectly. But problems occur when for example: Your boss tells another developer (me for example) to create a MySqlData class (also implementing DBMain and using a MySql database instead of a flat file) and then I have to hand over this MySqlData class to you and you have to change your program and start using the MySqlData class. Do you see what problems will occur?

I agree working with String-arrays is not that fun (and error-prone) and using a Room-object like you certainly is a good idea. I didn't use a facade in front of my Data class, but used a BusinessService interface. This interface uses the Room-objects in its methods and convert the String-array to an object or vice versa.

Kind regards,
Roel
 
Allan Cheong
Ranch Hand
Posts: 71
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see your point now. Thanks.
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I definitely agree with my good buddy Roel.

Allan, what I did (and Roel did as well) was create another interface, which extends the interface provided by Sun, and has a few methods. This new interface is implemented by the Data class, and the rules we have to follow are totally respected.

In a nutshell, what Roel is saying is that, if the client of a particular component references it by its API, then it gets more flexible, since it doesn't have to change to use another implementation of this component.
 
Allan Cheong
Ranch Hand
Posts: 71
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Roberto,

The assignment instruction states that


Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface:

package suncertify.db;

public interface DB {
.
.
.



If I create another interface SubDBInterface that extends DB, and Data.java implements SubDBInterface, that would be ok? I am just trying to avoid automatic failures.
 
Roberto Perillo
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Allan Cheong wrote:If I create another interface SubDBInterface that extends DB, and Data.java implements SubDBInterface, that would be ok?



Oh, certainly champion! I did that as well. In fact, a lot of people do that, in order to bypass some of the limitations that are present in the interface provided by Sun.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roberto Perillo wrote:In fact, a lot of people do that


I did that too and because me and Roberto both passed (together with a whole lot other ranchers), you are certainly not violating a must requirement.

Kind regards,
Roel
 
Allan Cheong
Ranch Hand
Posts: 71
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you both!
 
Those cherries would go best on cherry cheesecake. Don't put those cherries on this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic