Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS3220 Web and Internet Programming About Data Models

Similar presentations


Presentation on theme: "CS3220 Web and Internet Programming About Data Models"— Presentation transcript:

1 CS3220 Web and Internet Programming About Data Models
Chengyu Sun California State University, Los Angeles

2 Broadly speaking, the world
consists of things and actions performed by things or on things

3 Things and Actions in Computer Programs
Most of computer programs are created to help people solve problems in the real world (or in the case of video games, problems in imaginary worlds) Real World Computer Program Things Data Actions Actions (Operations)

4 Data and Operations in Programming Languages
Values (a.k.a. Literals) Variables Structs Data Functions Methods Operations

5 Data and Operations in OO Languages
Class { Fields Methods } Data Operations

6 Data and Operations in MVC
A class that represents only data Model Displays the result of an operation View Controller Implements an operation

7 Importance of Data Modeling
Data is half of your application If data is not modeled correctly, operations will be wrong no matter what you do

8 What's Wrong with the Code?
List<String> surveys = new ArrayList<String>(); List<String> questions = new ArrayList<String>(); List<String> choices = new ArrayList<String>();

9 What's Wrong with the Code?
public class Survey { String name; List<String> questions; List<String> choices; }

10 What's Wrong with the Code?
public class Survey { String name; String question; List<String> choices; }

11 What's Wrong with the Code?
public class Survey { String name; Map<String, List<String>> questions; }

12 Create Data Model Classes
Look for nouns in the problem description Simple types (e.g. number, string, data/time) become fields Complex types (i.e. things that contain other things) become classes Add an id field when necessary If it passes the "English test", it's probably a good class


Download ppt "CS3220 Web and Internet Programming About Data Models"

Similar presentations


Ads by Google