Tag Archives: Noun

MVC in Practice: Designing Models

Existing Examples

Sketch

There are lots of examples online teaching you what is MVC, why it is good and how to develop an application using this pattern. However most of them use a predefined structure with already constructed database and only the connection between a database table and a model is described. Actually what happens before all this. The client tells you something he’d like to have in his application.

Just imagine the following situation. You’ve a client who tells you that he wants a blog. The blog has to have posts and users, and every user must write posts and every post must have comments. Also he wants a set of categories where each post will be attached to one ore more categories. And finally a blogroll – one ore more links to another blogs.

This is pretty general and does not pretend to be a full featured example. However the strategy to make a primary structure of the future models is to pickup the nouns in this paragraph. It is really simple:

The blog has to have posts and users, and every user must write posts and every post must have comments. Also he wants a set of categories where each post will be attached to one or more categories. And finally a blogroll – one ore more links to another blogs.

So far you can see there are five prototypes of database tables: post, user, comment, category and link.

It’s important to note that not every noun is ready to be a database table. In some cases, when the client is really smart, he can give you a more detailed description. Than there are nouns describing the other nouns, of course, they are supposed to be columns to those tables.

Every post must have title and description

This is what we can do for now. From a raw text you can design your database and models in the MVC architecture.