aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: Adapter class 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 "NX: Adapter class" Watch "NX: Adapter class" New topic
Author

NX: Adapter class

Michael Dreese
Ranch Hand

Joined: Apr 02, 2003
Posts: 45
Hi all,
In my assignment, there is an required interface called DB and it comes with the following statement:
"Your data access class must be called "Data.java", must be in a package called "suncertify.data", and must implement the DB interface."
I'm confused about the above statement. What does the data access class mean here? Does the statement mean I can only have two files in suncertify.data - DB.java and Data.java? I'm thining to use Data.java (which implements DB interface) as an adapter class. Also, I implemented a class called Database that can provide all the methods that Data.java needs to implement for DB.java.
Can I use the adapter class here? Is my concept of adapter class correct?
Thanks for reading my post and I'd highly appreciate your helps.
Cheers,
Michael
Ramesh kumaar
Ranch Hand

Joined: Mar 19, 2002
Posts: 146
Hi,
You have to create an interface named DB with all the database releated methods like create, modify etc..
Now provide an implementation class named Data.java by implementing the above interface. thats about it. As for as my knowledge this can'nt be called as adapter pattern.

-rameshkumar
xin dong
Ranch Hand

Joined: Mar 24, 2003
Posts: 33
Yes,I think Ramesh is right.Of course you can use the adapter class here.But Data class is not a adapter class.it's just a class implements DB interface.
Michael Dreese
Ranch Hand

Joined: Apr 02, 2003
Posts: 45
Guys, thanks for your reply.
But I'm still confused about the adaptor class.
Let's say I have three *.java files - DB.java (interface), Database.java, and Data.java.
Data class must implement DB interface for the data access.
Data class "has" Database class's instance as a member variable. Database class gets to connect to the data file and has some similar methods that appear in DB interface. Then, I think the Data class is an adaptor class here.
In this case, am I applying Adaptor pattern correctly? Also, can I do it that way for my assignment? I'm just afraid I'm not following the exam instruction.
Please, bare with my english. It is not my native language. I will be happy to make my points clear if there is any confusion on my question.
Thanks in advance,
Michael
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
Hi Michael,
To me, it seems like Database is really just a Database driver: So is Data an Adapter to the driver? I guess you could think of it that way.
M


Java Regular Expressions
Michael Dreese
Ranch Hand

Joined: Apr 02, 2003
Posts: 45
Thanks alot, Max.
I think Data is an Adapter to the driver here since Data can access data file from the driver and hide the database from the client. I'm not sure whether I'm getting it right, tho.
Also, I'm more concern about whether I can do the way I want for my assignment. According to my instruction.html, it said "Your data access class must be called "Data.java", must be in apackage called "suncertify.data", and must implement DB interface." Does my Data.java satify the instruction?
Cheer,
Michael
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
It sounds just fine, though you could argue that Data is a proxy to Database.java.
M, author
The Sun Certified Java Developer Exam with J2SE 1.4
[ April 08, 2003: Message edited by: Max Habibi ]
Michael Dreese
Ranch Hand

Joined: Apr 02, 2003
Posts: 45
Originally posted by Max Habibi:
It sounds just fine, though you could argue that Data is a proxy to Database.java.

Max, would you mind to explain a little bit more about the difference between Adpater and Proxy? I'm kind of confused.
Also, does my design follow what the intruction requires?
Cheers,
Michael
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
A proxy object recieves methods calls on hehalf of another object: a Adapter provides an interface to a client, thus allowing the client to speak to an unknown implementation of that interface.
M, author
The Sun Certified Java Developer Exam with J2SE 1.4
Michael Dreese
Ranch Hand

Joined: Apr 02, 2003
Posts: 45
Originally posted by Max Habibi:
A proxy object recieves methods calls on hehalf of another object: a Adapter provides an interface to a client, thus allowing the client to speak to an unknown implementation of that interface.

Thanks for your explanation, Max.
But I still have a question on Adapter pattern.
Let's say I don't have my database class now.
I have a class called Data, which implemented DB interface. Since I think DB doesn't provide good enough functionalities for clients, I decide to create a class called DataAccess.
DataAccess will have same methods that DB has, but just their signature may have some differences (for example, instead of returning String[], it returns Record).
DataAccess will directly be used by clients, so the clients will not know the actual implementation.
Does the DataAccess consider as an Adaptor class?
I just want to know whether I'm getting the idea correct. Pattern design is very new to me and I'm trying to learn it right.
Thanks again, Max.
Cheers,
Michael
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NX: Adapter class