Forums Register Login

Design issue for simple Downloader

+Pie Number of slices to send: Send
Hi,

I have completed an exercise where one had to construct a simple class wich given a hostname, a portnumber and a filename would
download the file. This was to be done using only Sockets, so no use of eg. URLConnection.

I often get beat for putting too much in a single class, so now afterwards I am redoing the exercise trying to create some class-overload in a sensible way.

I have made a class HTTPRequest which wich holds info about the target to download: Hostname and path to target. The only
non-trivial method in this class is a method that writes an HTTP header to a given BufferedWriter returning the BufferedWriter after having written the 2 first
standard HTTP header request lines to it.

Now I cant really decide wether the Socket used should go inside the HTTPRequest class. My first thought was that it would make sense to have a Downloader class
which created the socket from a user-given hostname and port (which defaults to 80) which also created the appropriate HTTPRequest which would then write
the request to the OutputStream gotten from the Socket. But this looks a bit strange "conceptually" since now the hostname "sits" in two places, the HTTPRequest and in the Downloader. So where do I go wrong with my "modelling" ?
+Pie Number of slices to send: Send
One suggestion:

You pass the HTTPRequest object to the constructor of the Downloader class; then you use its getHTTPAddress() method whenever you need the address in the downloader.

Doubtless other people will have other suggestions, probably better than mine.
+Pie Number of slices to send: Send
I like this suggestion.
Thanks.

Adding more functionality to the Downloader it seems that everything would be more elegant using URLRequest. Strange requirement in the exercise to disallow this, basically you have to design a class thats already existing and in better design then one could do for now !
F is for finger. Can you stick your finger in your nose? Doesn't that feel nice? Now try this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 626 times.
Similar Threads
My SCEA Part 1Study Notes
reader interface, wait() then go
Protocols
Buffered Writer automatically does flush() on a close()?
Operation timed out
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:36:53.