• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

NX: Adapter class

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Michael Dreese
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
yeah, but ... what would PIE do? Especially concerning this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic