MVC, MVP, Presentation Model - which one?

P

py

I am working on creating a simple chat application. it will have a
buddy list, allow for chat 1 on 1 using a tabbed pane per conversation.

I expect to have a hierarchy of components like...

A Frame
main panel
buddy list panel
buddy list
chat tabbed pane
chat tab #1
chat panel
chat history panel
message input panel
chat tab #2
chat panel
chat history panel
message input panel
chat tab #n
chat panel
chat history panel
message input panel

Then I will have a Model which stores a list of Buddy objects and
maintains the current users name and IP address. When new messages
come in off the wire I will need to notify the model and views so they
can display the message, same goes for when a buddy signs on or signs
off.

Anyway, I am trying to figure out the best way to code this up, using
MVC or MVP or Presentation Model, any suggestions? Links to examples
or things of that sort are helpful.

Thanks in advance for any input.
 
W

Wesley Hall

Anyway, I am trying to figure out the best way to code this up, using
MVC or MVP or Presentation Model, any suggestions?

Scratch the presentation model immediately, it is essentially MVC but
with an odd merging of the model and controller, and there is good
reason to seperate them.

I had not really heard of MVP so I did a little reading and it seems to
be an interesting idea and a logical step forward from the MVC pattern
that I am used to.

The advantage of MVP is that there is an addition 'Presenter' object in
the standard MVC structure, the presenter knows the controls available
to view and has the data available in presentation format but not how to
display it, which is the view's task.

To be honest, I think the MVP pattern would be overkill for most
projects, it would only repay the effort if you were certain to need
many different types of presentation. I doubt a chat application would
fall into this category. MVC would be my choice. Although, "wanting to
learn MVP" might be reason enough :)
 
P

py

I agree MVC is probably best for this case.

Problem I have is how to notify each panel, component when a something
happens, say a message is received. How do i link these together
without having all view code in one giant class?
 
C

Chris Uppal

py said:
Problem I have is how to notify each panel, component when a something
happens, say a message is received. How do i link these together
without having all view code in one giant class?

Design the application level code (i.e. non-GUI or "domain" code) first. So
you might have (just for example) an instance of ChatApplication which
contained a BuddyList and (dynamically) zero or more ChatServers, plus (even
more dynamically) zero or more Conversations.

The visible part of the overall application would contains a "My buddies"
tab -- which would be connected to the BuddyList instance as its Model, and one
or more "Chatting with Bob" tabs, each of which would be connected to one of
the Conversation as its Model. Each of the tabs would be/hold an instance of
its own class (just one instance of BuddyListPresenter and several instances of
ConversationPresenter). Those panels would Observe the changes to the
Conversations (and so on), and update themselves accordingly. Similarly the
overall window would Observe the ChatApplication (its own model) and would
add/remove "Chatting with.." tabs as Conversations started up or died.

On-the-wire events (incoming messages) would be routed from the ChatServers to
the Conversation objects and so reflected in the "Chatting with..." tabs. Or
via the BuddyList to the "My buddies" tab.

The important point is that you have a nested structure of Models, and a (more
or less) corresponding structure of "presenters" which know how to control and
display the changing state of their models.

If you want to take my use of the word "presenter" as implying that I favour
MVP... Well, that's true, I do, but all I mean by the word here is "that which
implements the presentation".

If you want an easy test for whether you've got the separation right (and I
know that you didn't even hint that you did ;-) It should be a trivial matter
to extend your application so that the user can spawn off any particularly
interesting conversation tab into a separate top-level window (obviously that
would take some extra Swing code to open the window, but it shouldn't require
much more than that).

-- chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top