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.
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?
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..
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.
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.