wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Awareness of the data model Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Awareness of the data model" Watch "Awareness of the data model" New topic
Author

Awareness of the data model

Jonathan Elkharrat
Ranch Hand

Joined: Dec 31, 2008
Posts: 170

is this a good design?

i designed my server and DAO to be not aware of the actual data format.
the DAO delegate the "hard work" to some static methods in a "util" class
(e.g. the converting of record to array and vice versa - used at startup and
shutdown, and validating data)
the server too, deal with dummy room class that know how to to convert
from and to a string array, but the server itself know nothing about the
format of the array it's dealing with.

i'll give a little sample from the book method, just to demonstrate:

the server doesn't know the format of the array (which is, in my opinion
a good thing if tommorow they change the data format. same for DAO,
it contain only logic, everything data-specific is delegated to a "util" class)



is it a good way to design components? or am i doing not necessary overkill?


SCJP 5, SCWCD 5, SCBCD 5
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2247

Howdy, Jonathan!




the server doesn't know the format of the array (which is, in my opinion
a good thing if tommorow they change the data format. same for DAO,
it contain only logic, everything data-specific is delegated to a "util" class)


Ok, this is good. I'd only try to find more appropriate classes to put logic in and avoid these "util" classes (even though it is not possible to avoid them most of the time). For instance, instead of creating an util class to transform a Room object to array, you put this logic in the Room class itself, which is very good.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Jonathan Elkharrat
Ranch Hand

Joined: Dec 31, 2008
Posts: 170

maybe i didn't explained myself enough.

the only static functions are the one used at startup and shutdown (for read and write)
and the validating function, all these were delegated to some util class in ths same package
as the DAO, which use them when necessary (this clean the DAO from data specific logic,
which can be "ugly" sometime).


the code snipet doesn't contain static method, it just show that the server doesn't know
anything about the format of the data (this is why i don't replace these 4 lines with one
line: record[record.length] = customer)
the read method is the implemented read() i wrote, and it operate on an instance of DB inteface..

Roberto Perillo wrote:
For instance, instead of creating an util class to transform a Room object to array, you put this logic in the Room class itself, which is very good.


the coversion to and from is indeed in thr Room class itself: record = room.toArray();


Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4919
    
  10

My Data class contains the validation of the data according to the database schema: the String[] is passed to a seperate (private) method which checks if this array is valid (array length, size of strings,...). When an array is invalid an IllegalArgumentException will be thrown; of course this exception will never be thrown in a well-developed and well-tested application, because that would indicate a developer's mistake. The Data class is completely unaware of the type of records it is processing, e.g. you can point the Data class to a similar database file containing hotels or customers and you'll be able to use the same Data class for CRUD-operations (of course with another client).

My business service is aware of the type of objects it has to handle, because it is a business service especially for rooms, but the service does not know anything about the format of the array (just like you). I decided to create a utility class for handling a bunch of "room" actions, e.g. converting String[] to Room-object (and vice versa of course)


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Awareness of the data model
 
Similar Threads
Saving details of rooms
URLyBird Data Access Package Design
Adding JLabels to a vector
Object trouble.
if statement