This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes OO, Patterns, UML and Refactoring and the fly likes HFDP: Where to put Network Connection in MVC? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "HFDP: Where to put Network Connection in MVC?" Watch "HFDP: Where to put Network Connection in MVC?" New topic
Author

HFDP: Where to put Network Connection in MVC?

Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Dear all,

after reading about MVC in HFDP (p. 526f) I like to know where the best place in MVC is for a network connection.

My first thought was to put a network connection into the Controller, but reviewing some examples I saw that a network connection is put into the Model.

Do you agree that the Model is the right place for a network connection to connect to a database for example ?

Regards,
Darya
[ April 13, 2005: Message edited by: Darya Akbari ]

SCJP, SCJD, SCWCD, SCBCD
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
In my world the model does the things that require networking, like connecting to partner systems for various services. The database is hidden behind the model for sure. What other kinds of network connections would you have?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi Stan,

I always count on what you say . My first thought was that the Controller is of control for everything in MVC.

Now I think the Model is the best place, simply because of the model's tight relation to a connection like a database connection.

In addition the controller can delegate it's connection related stuff to the model.

Thanks,
Darya
[ April 14, 2005: Message edited by: Darya Akbari ]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Sounds good. The controller just kind of organizes work done by others and shouldn't get at all fancy.

You could make a case for exceptions to all this where the model, view and controller all communicate with each other over networks. For example when my servlet controller talks to an EJB model it's technically over a network protocol, but networking is hidden from me by the frameworks I use. I don't show the network on application design diagrams, but I do show it on deployment diagrams where I need to talk about load-balancing and redundancy.
[ April 14, 2005: Message edited by: Stan James ]
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi Stan,

I am sure that I will come back to you when I start Sun's SCEA . For now I'm goig to finish SCJD and your first hint is already valuable to model my GUI layer.

Thanks a lot,
Darya
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Stan James:
The controller just kind of organizes work done by others and shouldn't get at all fancy.


:eeek:

In MVC, the *sole* responsibility of the Controller is to handle *input* into the system (such as button clicks in a Swing application or web requests in a web application).

So, if you see network traffic as input to the system, a Controller would be the right place to put the networking code. The Model then shouldn't know at all wether a request was initiated by a click in the GUI or some network request.

If network traffic is more bound to business logic, it's place is somewhere in the model.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Ouch, that was a sloppy description of controller, wasn't it. My favorite is that it "interprets user gestures" from the view, e.g. it maps clicking button x to trigger business process y. User gestures on the web are pretty big and crude - a GET or a POST with some parameters.
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi Ilja and Stan,

My application (SCJD assignment) contains a Connection object which at runtime is a LocalConnection or a RemoteConnection (RMI) object. The connection hides a data file (table).

For the GUI layer I plan to let the Model object represent the data file as AbstractTableModel (Model extends AbstractTableModel). Hence I place the Connection object into the Model while the Controller object only provides the business methods needed.

In this case I don't see a reason why I should place the Connection object into the Controller

Can you agree with it

Regards,
Darya
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Yes, you're good there.
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Thanks for your feedback. I go back to finish my SCJD assignment.

Regards,
Darya
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HFDP: Where to put Network Connection in MVC?
 
Similar Threads
B&S: Need some clarification on the single mode flag
MVC question
Head First OOAD
Design Patterns used in Max's book
HFOOAD my first impression: Why is J2EE not covered?