Principles of MVC: It's Always a Good Practice to Learn the Curve before Head
PHP is one of a variety of sought-after skills as demand heats up this year. The technology has been condemned to death more than once & managed to come back stronger than before. The following post emphasizes on certain principles of MVC to focus upon.
PHP is one of a variety of sought-after skills as demand heats up this year. The technology has been condemned to death more than once & managed to come back stronger than before. Well, I am not a PHP evangelist. All I need to say that today one can do everything thought that was only possible in imagination. The following post emphasizes on certain principles of MVC to focus upon.
What is MVC? I am sure you must have happened to go through several articles or tutorials that make use of terms like "business logic" without really defining what it means. This makes understanding MVC all the more difficult. Whereas, others simply gross over what an architectural pattern is without even incorporating why one should even consider it? By now you must have known that my perspective on MVC is through PHP. After spending many years in developing scalable, R.A.D. PHP Frameworks, I have come to a conclusion that MVC is very powerful, scalable, clean, of course, if well-coded.
Model-View-Controller (MVC) a software architecture or design pattern is mainly based on the idea that the logic of an application should be separated from its presentation. In simple words, it is the best way to separate the logic of your application from the display. The main agenda of MVC is to separate the application into 3 main parts, i.e. model, view, and controller.
Consider the above diagram, you will find direct associations (solid lines) and the inferred associations (dashed lines), the dashed lines are the ones that might seem apparent from the point of view of the user whereas direct ones are from the actual software design. A simple step by step guide includes:
• A user interacts with the view- by clicking on a link or submitting a form
• The user input is successfully handled by the controller, transferring information to the model
• The model receives the information and updates its state (adding data to a database, calculates today's date, etc)
• The View checks the state of the Model and responds accordingly to the newly entered data, maybe.
• The View waits for another interaction from the user.
If you ask me in person, MVC has a really good philosophy. In fact, the idea of separating the logic from the display isn't new but it's MVC that presents idea so nicely. Besides, code presentation and layout are simply making your application more maintainable. Business Logic
How will you react when I say that the term doesn't really have a definition that can be defined properly? Yes, the concept is pretty simple. It's the process of calculating the logical processes of an application. What I mean is, you can use a simple calender's business logic to calculate what today's date is, what day it is, and on what day all of the days in this month fall, etc.
So, the conclusion is don't let yourself get bullied by such flashy terms. Business Logic is nothing but just a processing part. Templates
If you take a closer look at PHP development in India, I am sure you will find that many MVC frameworks using the same sort of template system to enforce the principle of DRY, making it really easy to re0use code without having to rewrite it. It is very important for you to know that some template engines have rather complicated syntax- so don't forget to check them out right before you start developing. And there is no need to learn a whole new language only to get a page to render. DRY
Another great implementation of MVC is DRY (Don't Repeat Yourself) philosophy. One would imply that changing one element of the system does not change unrelated elements, which is rather logical. I would personally like to recommend that Ruby on Rails pulls this off in the best way, and does it most simply. Convention Over Configuration
Being a design paradigm, it tries to remove the amount of decisions you, as a developer, need to make. A developer only needs to change the things that really need to change. Take an example of a form: It must be comprised of elements that are always required and those elements have states that are usually the same. Applying this idea to all elements makes building this type of application very fast, easy and simple.