Why separate the URL request and the URL connection?


#1

I am wondering, why do we put the creating of the URL request in one object (BNRFeedStore), and the creating of the connection in another object (BNRConnection). Why not pass the URL string to the connection object and let it do all of the connection-related work?

I realize that there often is more than one correct way to implement a solution, and I also realize that sometimes the book authors do things in a certain way for the instructional value. However, I am very interested to know, is there a technical reason why the BNRFeedStore class creates the URL request, and not the BNRConnection class?

Thanks.


#2

I think the reason are the MVCS - design pattern and the fact that BNRConnection objects are the minions of BNRFeedStore. The store tells his actor: “Get me the data from this URL: XY” and the actor builds up the connection and gets the data.


#3

I agree with your reply, Crumble. I still wonder why create two related objects in two different classes, and not pass a string to the object doing all of the connection work.

It might just be a matter of style.


#4

[quote=“wagill”]I agree with your reply, Crumble. I still wonder why create two related objects in two different classes, and not pass a string to the object doing all of the connection work.

It might just be a matter of style.[/quote]

I think this is more a case of abstracting the object types so that extended functionality can easily be accommodated with the least risk of breaking encapsulation. So for example if we needed to extend Connection to include new types of connections, then the code is more manageable. I also find that my programs load more quickly when I keep the source files smaller.