This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
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

DB Interface (URLyBird 1.1.2)

 
Allan Cheong
Ranch Hand
Posts: 71
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • 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.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • 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: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see your point now. Thanks.
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • 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: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic