2016年9月9日星期五

Week7 MVC & Database design

In this week lecture, we were discussed about various of patterns, these patterns are useful when generate repeatable solutions to commonly occurring problems in software design. There is a very important pattern which is model-view-controller is highly related for our concept back end design.

Models represent knowledge, a model could be a single object, or it could be some structure of objects, so the model for our concept is the database structure, which include adding and retrieving items from DB, processing data from/to the DB and only connect to the controller. The view is a representation of the model, in our case, it’s the client side or front end, which include HTML and CSS, also the browser. The view also speaks only with the controller. A controller is the link between a user and the system, it can processes GET/POST/PUT/DESTROY requests (by using PHP) and handle all other server-side logic. The processes steps are 1. takes information from user 2. processes information and talks to the database if needed 3. Receives information from database 4. Speaks to view to explain presentation to the viewer (how display data to the screen).

Our concept back end is similar with model-view-controller pattern. When user want to view a dream, after he click the dream icon, then a request sends to the controller, PHP will access the database, then process the request and get the data, controller then send the data to the font end, the dream detail shows on the screen with an appropriate format and layout.

 
MVC




For our concept database design, firstly, I create a relational schema to define each table and their relationships. According to our original concept, there are three tables, the first table is “orb”, it includes two attributes which are orb ID and dream description, another table is “image”, also include two attributes which are image ID and image URL, the third table is “emotion”, it consists of emotions and emotion ID. There are two relationships, the first relation is: an orb must have two images, an image may be used by many orbs. The second relation is: each orb must have one emotion, and each emotion may belong to many orb.  


Relational Schema


Tables in phpmyadmin 

For the data type, I set all IDs as INT type, because they are numbers, so integer is a better choice.  I also set other attributes as VARCHAR type, because VARCHAR represent character string.

Primary keys: orb ID, image ID, motion ID
Foreign key: Table “Orb” (image ID) --à Table “image” (image ID)  , this may change after relational Mapping, because it’s M:N relationship
           Table  “Orb”(Eid) --à Table “emotion” (Eid)

Emotion table structure
Image table structure
Orb table structure
Relationships


没有评论:

发表评论