Sunday, February 17, 2008

mvc

The MVC(Model View Control) model - sees diagram - controller
MVC and template concept comprehend
The MVC originally exists in Desktop procedure, the M is an index number according to the model, the V means customer's interface, C then controller.The purpose which uses MVC is the code separation of the carry out of M and V, make the same of procedure be able to use a different manifestation thus.For example a batch of covariances data you can mean with the pillar form diagram, a round flat cake diagram respectively.The C existent purpose then insures M and V of synchronous, once the M change, the V should synchronously renew.
The model - sees diagram - controller(MVC) is Xerox PARC in the 80's for weave the distance language Smalltalk - 80 inventions of a kind of software design mode, up to now already drive extensive usage.Is recommend for the last few years for the design of the Sun company J2 EE terrace mode, and is subjected to more and more welcome of developer of use the ColdFusion and PHP.Model -'s seeing the diagram - controller mode is an useful tool box and it has a lot of advantages, but also has some weakness.
How does the MVC work
The MVC is a design mode, it is constrained to make importation of apply the procedure, handle and output to separate.Use a MVC application procedure to be been divided into three core partses:Model, see diagram, controller.They respectively handle own mission.
See diagram
See the diagram is a customer to see combine with its lternant interface.Apply procedure to say to the Web of old style, see the diagram is the interface which constitutes to°from the HTML chemical element, in the Web of the new style the application the procedure, the HTML still keeps playing important role in see the diagram, but some new of the technique has already pile up one after another, they include Macromedia Flash and the elephant XHTML, XML/XSL, WML etc. some marking languages and Web services.
How handle interface of apply the procedure to become to more and more have a challenge.MVC a big advantage is it can for you of the applied procedure handle a lot of differently see diagram.In fact have no real processing occurrence in see the diagram, ignore these datas is allied the machine save of be still an employee row form, conduct and actions see diagram to speak, it is a kind of exportation data to also allow the way that the customer manipulate.
Model
The model means business enterprise data and business rule.In MVC three partses, the model owns the most processing mission.For example it may use elephant EJBs and ColdFusion Components thus of Gou piece the object come to processing database.The data been return by the model is a neutral of, be say that the model has nothing to do with the data format, so a model can see diagram to provide a data for many.Because apply to need to be write at code of model can be seen diagram by many at a time heavy use, so reduced the repeated of the code.
Controller
The controller accepts an input of customer and adjust to use model and see diagram to complete the customer's need.So when single shot Web hyperlink within page with send out a HTML form and list, the controller doesn't output any thing and do any processing.It just receives to request and decide to adjust to use which model Gou piece whereabouts reason claim, then use to make sure to use which the data which depend on diagram to show that the model processing return.
Now the processing process of our summary MVC, the controller receives the customer's claim first, and decide should adjust to use which model to carry on a processing, then the model use business logic to handle a request of customer and return to a data, the controller finally uses to homologously see a diagram format to turn the data that the model return, and pass to mean that the layer presents to the customer.
Why want to use MVC
Greatly parts of Web application the procedure all uses to be like ASP, PHP, perhaps CFML so of the process turn language to establish.They will be like such data layer of the database search language sentence code with be like HTML thus of mean 1 F code mixs together.Experience more abundant developer would data from mean 1 F the separation open, but this usually very easily attains, it needs with meticulous care of plan and continuously try.MVC by the root constrained separate them.Though structure MVC application the procedure demand be some additional of work, but it brings us of the advantage there's no need to query.
First, most 1:00 of importance be that many sees diagram and can share a model, now applied procedure that need to be come to visit to ask you with more and more ways.To this, solution of an among those uses MVC, regardless you of the customer want Flash interface or WAP interface;Use a model can handle them.Because you already data and business rule from mean the layer separate, so you can maximize of heavy use you of code.
Because the model return of the data have never carried on a format to turn, so same of Gou piece the ability be use by the different interface.For example, a lot of datas may mean with the HTML, but they also probably want to use Macromedia Flash and WAP to mean.The model also has the function that appearance management and data hold out for long time sex processing, for example, according to shopping car and electronic commerce process of conversation also ability drive Flash website perhaps wireless allied the applied procedure of net heavy use.
Model is from include, and with controller with see diagram to mutually separate, so very easily change you of applied data layer and business rule of procedure.If you want to make you transplant the Oracle of the database is from the MySQL, or change you of arrive LDAP according to the RDBMS data source, the model which need to change you then.Once you correctly carried out model, the data which ignores you came from database or LDAP server and see the diagram will correctly show them.Because three partses of the applied procedure of usage MVC are independent mutually, change an among those will not influence other 2, so thought according to this kind of design you can construct good of loose accidentally match of Gou piece.
To me, the controller also provided an advantage, be can use controller to allied connect different model with see diagram to complete a customer of need, so controller can for construct application procedure to provide powerful means.Give settle some heavy the model use with see diagram, the controller can carry on a processing, then choose to see diagram and will handle a result manifestation to the customer according to the customer's need choice model.
MVC weakness
The MVC weakness is because it doesn't have explicit definition, so complete comprehension the MVC isn't very easy.The plan used a MVC demand with meticulous care, because it of the internal principle be more complicated, so need to cost some time to consider.
You will have to cost considerable time to consider how make use of the MVC to you of applied procedure, in the meantime because of model with see diagram to want strict separation, so also give adjusted to try application procedure arrival certain difficulty.Each Gou the piece is before use all need through exhaustive test.Once you of Gou piece through test, you can have no to have scruples about of heavy use them.
According to developer experience, was divided into an application procedure three partses because of the developer, so use MVC also means in the meantime that you will manage ratio before more documents, this is obvious.Seem so our workloads increased, but please remember this compare with it can bring us of the advantage be unworthy a lift.
The MVC also isn't suitable for small scaled even the applied procedure of medium etc. scale, cost a great deal of time to apply to MVC scale isn't very big of applied the procedure usually lose more than gain.
The MVC is a good path which establishes software
MVC design mode is 1 are easy to establish software of path, it is some principles promote and be like a contents and show mutual separate probably better comprehension.But if you have to insulate model and see the Gou piece of diagram and controller, you probably the applied procedure that need to be re- considered you be particularly the frame of applied procedure.If you be willing to accept MVC, and have ability to cope with its dditional work and complexity bring, the MVC will make you of the software is in the haleness and the code is heavy to use with the structure previous and new step.
The Web Application of the Java development has a few kinds to match a MVC design the development method of the mode.
1:Jsp+Servlet+JavaBean(EJB)
2:Jsp+JavaBean(Controller)+JavaBean(EJB)(Model)
3:TDK(Turbine, Velocity...)
4:Xsp
5:Jsp+Struts+JavaBean(EJB)

No comments: