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
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.
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.
Joined: Apr 02, 2003
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
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
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
town drunk ( and author)
Joined: Jun 27, 2002
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
Joined: Apr 02, 2003
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