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 / First Aid / December 2006

Tip: Looking for answers? Try searching our database.

Model-View-Controller

Thread view: 
Aned - 07 Dec 2006 23:28 GMT
considering reuse at the source code level, what are the
characteristics that discriminates a model from a view or controller.
in other words, if some one gave me a peice of source code, is it
possible to tell whether it is a model or a view or a controller just
by reading through the source code?

the reason of having such a pattern is to facilitate the idea of
separation of concerns, it is comonly known that at the conceptual
level, it is possible to replace a model component with another one
that satisfy the model characteristics, but is that feasible at the
source code level?

thanks
Lew - 08 Dec 2006 03:12 GMT
> considering reuse at the source code level, what are the
> characteristics that discriminates a model from a view or controller.
> in other words, if some one gave me a peice of source code, is it
> possible to tell whether it is a model or a view or a controller just
> by reading through the source code?

More or less, and it depends on the source code.

Consider what the terms "model", "view" and "controller" mean in this context.

"Model" is the business logic, so if you see a piece of code (be it class,
method or just a paragraph in a method), if it deals primarily with business
logic it's part of the "model".

"View" is the presentation, or the part with which the user interacts.
Typically this means the GUI (or command line), and the artifacts that
directly create the display and handle input. So if you see a form, dropdown,
button or the like that is part of the "view".

The "controller" has two main purposes - linking other components to each
other and managing navigation from screen to screen (or process flow module to
module). A controller component will invoke the correct model code in response
to a user input, say, or move the user from one page or screen to another.

Much real-world code intermingles these roles in a single code block or
artifact. You will probably encounter code that analyzes a screen input
(view), does some sort of business action such as a database update (model),
decides what screen to show next (controller) and moves the user to that
screen (view), all mixed together.

Well-written code will move these aspects into separate code blocks, usually
separate classes. For example, the Swing API includes JTable, a view
component, and TableModel, a model component. The JTable displays information
contained in the TableModel. One could display the information in some other
way than a JTable and still maintain its integrity as information in the
TableModel.

- Lew
Ed - 08 Dec 2006 20:30 GMT
Aned skrev:

> considering reuse at the source code level, what are the
> characteristics that discriminates a model from a view or controller.
[quoted text clipped - 9 lines]
>
> thanks

At least in the View will be easily distinct from both Controller and
Model at source code level (which, by the way, is the only level on
which MVC operates; at least there's no MVC at execution level ... ok,
it may/could exist at distribution level, but this is secondary to
source code concerns). The View will be the only one with large amounts
of HTML or Swing or println()s.

Here's a test for you: look at a few random classes from the model,
view, and controller subpackages here and see if think you could spot
the primary concern from the code if you couldn't see the package
structure:

http://www.edmundkirwan.com/servlet/fractal/cs1/code/all-link0.html

.ed

--

www.EdmundKirwan.com - Home of The Fractal Class Composition


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.