Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

MVC, MVP, Presentation Model - which one?

Thread view: 
py - 02 Nov 2006 16:12 GMT
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.
Wesley Hall - 03 Nov 2006 00:18 GMT
> 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 :)
py - 06 Nov 2006 18:11 GMT
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?
Chris Uppal - 06 Nov 2006 19:31 GMT
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.