Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFDP: Where to put Network Connection in MVC?

 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you're good there.
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your feedback. I go back to finish my SCJD assignment.

Regards,
Darya
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic