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" ?
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" ?