Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm in my second java course at school and am thinking of developing a web service client library for one of my projects. I'd like the library to be able to query the MusicBrainz web service and have it return a data object or search results depending on the query.

Does anyone have any advice or a reference that I can be pointed to? Specifically, I'm looking for advice on how to structure my code (e.g. how do I break up my classes) as well as help understanding how communication should flow from some external app, my library, the web service, and back.

There is an existing MB java client library, but I am trying my hardest not to go rummaging through it. I want to have the satisfaction of building my client from scratch and not just copy/pasting code and ideas from the existing app.

Edit:

Just to be clear, I'm not saying that I want to avoid looking at other libraries. What I meant above is that I know that there is already a library that does what I'm looking for, but since I'm fairly new at this stuff I want to avoid the temptation of just blindly copying ideas when I get stuck or when I'm not sure which direction to go in. Having multiple references would hopefully put me in a better position to know what to do.

What I'm looking for is some kind of reference guide I can use to build my own library. I haven't found much on my own so I thought posting a question on here might give me a few ideas or some new things to check out.

share|improve this question

closed as unclear what you're asking by MichaelT, GlenH7, Kilian Foth, BЈовић, Ozz Jul 9 '13 at 7:10

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

2  
"There is an existing MB java client library, but I am trying my hardest not to go rummaging through it. I want to have the satisfaction of building my client from scratch" This makes no sense. I can understand wanting to do it yourself, but then why ask a bunch of strangers on the internet for vague advice? If you are new to this sort of application then looking at a working example is one of the most effective things you can do. Being able to read and understand other people's code is a valuable skill. If you are trying to learn don't just copy and paste! Read, understand, and reimplement. –  Charles E. Grant Jul 9 '13 at 0:15
    
Okay, how about this. Do you know of any other similar apps that I can look through? I am willing to look through other people's code and understand how they did things. I just felt that if I look through the existing MB app I'd end up writing very similar code. –  Pavan Chander Jul 9 '13 at 1:51

3 Answers 3

up vote 0 down vote accepted

I have always struggled with this question (How do you design systems/libraries?). Most answers are along the lines of, with practice. So try and as you are trying to use your library constantly think about what is working well and what isn't, and adjust the library as you go.

How To Design A Good API and Why it Matters from the Google Tech Talks has some of the best practical advice I've come across:

http://www.youtube.com/watch?v=aAb7hSCtvGw

What I gleaned from it is: gather the requirements as user stories from the stake holders (only yourself in this instance), write up an initial guess of the interface, evaluate the interface with the user stories, take the initial interface to the stake holders and get their feedback, and try to write (a) simple program(s) that use the interface. After each step adjust your guess so that it is better.

After you feel you have a good enough interface that meets your requirements write the initial pass of the library and a few idiomatic programs that use the library.

After every step and as you are writing programs that use your library you'll realise better ways of doing what you are trying to do, areas you have missed, and easier ways of interacting with your library. Anything you find repetitive or hard is a prime candidate for improvement.

share|improve this answer
    
I finally got around to watching that tech talk. Thanks. The bit about writing simple programs that use the interface before it's been fully developed was very valuable. –  Pavan Chander Jul 10 '13 at 23:56

I see your situation as being like a novelist wanting to learn how to write a novel, but wanting to avoid reading other books so as not to borrow similar writing styles. While you certainly don't want to copy the same plot ideas or words from a book about the same subject (that'd almost certainly result in plagiarism), you're going to have an incredibly difficult time writing if you avoid reading altogether. However, you might check out books in related genres (or sometimes the same one to see what the standard is) to get a better feel for how others effectively (or not so effectively) write.

Bringing it back to code, wanting to write a software library yourself is certainly admirable, but you're going to have a hard time learning how to do it if you aren't looking at other people's code. Generally speaking, it's hard to find good tutorials or documentation that codifies how to do specific things like what you're wanting, so one of the most effective ways to learn is to look at similar code and understand how it works (as Charles noted in the comments, understand it, don't just copy-paste!)

In my analogy, I said that a writer might read works from an author in a related genre to better understand how they might write. If you don't want to look at the code for the MB Java Client Library, look at code for something that does something close, but not the same. For instance, you could check out some other library that queries online data (maybe sports scores or Twitter feeds) and see how they do things. Especially since they will return different types of data, you'll have to understand what is going on if you are going to be able to apply that information to be able to program your own library.

EDIT: Also, looking at a library that does the same thing can be a good checkup, once you understand how to program it. Ask yourself how you would do it, see how they did it, and then ask yourself if your idea was better or if theirs was.

share|improve this answer

Libraries are reusable code. So if you want to create reusable code you must first use it.

I would start writing an app that needs the functionality of you library. implement that functonality in the app. when the app is done try to refactor the functionality-code into a seperate class/module/library. when this is done you can refactor this library into a webservice.

share|improve this answer
    
That's a good idea. I might do this instead of just jumping in and writing a somewhat abstract library. –  Pavan Chander Jul 9 '13 at 7:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.