28
CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak www.cs.sjsu.edu/~ mak

CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Embed Size (px)

Citation preview

Page 1: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

CS 160: Software EngineeringOctober 15 Class Meeting

Department of Computer ScienceSan Jose State University

Fall 2014Instructor: Ron Mak

www.cs.sjsu.edu/~mak

Page 2: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

2

Midterm Question 1

Briefly discuss how each of the following software engineering techniques, technologies, and methodologies deal with the challenges of complexity and change.

Model-view-controller (MVC) architecture

complexity Break a GUI application into three coherent, loosely-coupled parts. Enable parallel development.

change Changes to one part won’t affect the other parts.

Page 3: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

3

Midterm Question 1, cont’d

Agile programming

complexity Break development into multiple short iterations. Each iteration has design, code, and test. Always build on already working code.

change Not the old waterfall model. Able to handle design and requirements changes.

Page 4: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

4

Midterm Question 1, cont’d

Client-server architecture

complexity Break a web application into three coherent, loosely-coupled parts. Enable parallel development.

change Changes to one part won’t affect the other parts.

Page 5: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

5

Midterm Question 1, cont’d

Data access layer

complexity Encapsulate database connection, JDBC, etc. from the rest of the

application. Object-relational mapping.

change Isolate changes in the application code and in the database structure

from each other.

Page 6: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

6

Midterm Question 1, cont’d

Database table normalization

complexity Eliminate multi-valued fields, repeating fields. Make tables coherent.

change Easier to modify tables via insert, delete, and update operations.

Page 7: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

7

Midterm Question 2

You are going to develop a new version of the online class registration system that you use to sign up for classes each semester.

List seven (7) functional requirements.

1. Students shall log in securely with their student IDs.

2. System shall access the SJSU courses database.

3. Administrator shall be able to add, delete, modify classes.

4. Students shall add and drop displayed classes.

5. System shall check course prerequisites.

6. System shall check for time conflicts.

7. System shall maintain wait lists.

Page 8: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

8

Midterm Question 2, cont’d

List three (3) nonfunctional requirements.

1. System shall be web-based.

2. System shall be secure from hackers.

3. System shall respond within 1 second.

Page 9: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

9

Midterm Question 2, cont’d

Draw a UML use case diagram that shows at least two (2) actors and five (5) use cases.

Start up system

Shut down system

Update classes

Add class

Drop class

admin

studentdatabase

Page 10: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

10

Midterm Question 3

You are going to use Java on the server to implement the class registration system in Question 2.

Briefly name and describe three (3) servlets.

LogInStudent Log in a student securely using the student’s ID.

AddClass Student adds a class.

DropClass Student drops a class.

Page 11: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

11

Midterm Question 3, cont’d

Briefly name and describe three (3) JSPs.

LogInPage Displays the log in form.

ClassListPage Display the list of classes the student can choose from.

SchedulePage Display a student’s class schedule.

Page 12: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

12

Midterm Question 3, cont’d

Briefly name and describe four (4) JavaBeans.

Class A class that a student can take. A prerequisite class

Student A student.

Admin An administrator.

Schedule A student’s class schedule

Page 13: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

Midterm Question 4

Our example school database needs to support team teaching, where more than one instructor can teach a class.

Draw an ER diagram.

13

FK

PK

FK

FK

FK

PK

FKFK

PK

PK

Page 14: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

14

Midterm Question 4, cont’d

Write the Java method

that uses JDBC and prints the results of the query:

CommonClasses(int teacherId_1, int teacherId_2)

Given two teachers, which classes do they teach in common?

Page 15: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

15

Midterm Question 4, cont’d

The 10-point description:

We can assume the method can be called multiple times, so we should use a prepared statement. The preparedstatement uses a teacher ID to make the query thatreturns the classes taught by that teacher. We can also assume that we’ve already defined a Klass JavaBean to represent a class, and we’ll use object-relational mapping to put the returned Klass objects into an array list.

We’ll use the prepared statement to generate two arraylists of Klass objects, one array per teacher.

Then we’ll use Java to find and print the common classes.

Page 16: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

16

Midterm Question 4, cont’d

The 15-point solution:

private static String CLASSES_OF = "SELECT code, subject " + "FROM class, teacher_class " + "WHERE teacher_id = ? " + "AND code = class_code”;

private static Connection conn;private static PreparedStatement ps1;

conn = DriverManager.getConnection (DB_URL, USERNAME, PASSWORD);ps1 = conn.prepareStatement(CLASSES_OF);

Page 17: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

17

Midterm Question 4, cont’d

private static ArrayList<Klass> classesOf(int id) throws SQLException{ ArrayList<Klass> klasses = new ArrayList<>();

ps1.setInt(1, id); ResultSet rs = ps1.executeQuery();

while (rs.next()) { Klass klass = new Klass(rs.getInt("code"), rs.getString("subject")); klasses.add(klass); }

return klasses;}

Return an array list of classestaught by the teacher.

Object-relational mapping.

Page 18: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

18

Midterm Question 4, cont’d

private static void commonClasses1(int teacherId_1, int teacherId_2) throws SQLException{ ArrayList<Klass> klasses_1 = classesOf(teacherId_1); ArrayList<Klass> klasses_2 = classesOf(teacherId_2);

ArrayList<Klass> common = new ArrayList<>();

for (Klass k1 : klasses_1) { for (Klass k2 : klasses_2) { if (k1.getCode() == k2.getCode()) { common.add(k1); } } }

printCommon(common, teacherId_1, teacherId_2);}

Array list ofcommon classes.

Page 19: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

19

Midterm Question 4, cont’d

An alternate solution Requires a bit more advanced SQL.

private static String COMMON_CLASSES = "SELECT code, subject " + "FROM teacher_class tc1, teacher_class tc2, class " + "WHERE tc1.teacher_id = ? AND tc2.teacher_id = ? " + "AND tc1.class_code = tc2.class_code " + "AND tc1.class_code = class.code " + "ORDER BY class.code";

private static PreparedStatement ps2;

ps2 = conn.prepareStatement(COMMON_CLASSES);

Page 20: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

20

Midterm Question 4, cont’d

private static void commonClasses2(int teacherId_1, int teacherId_2) throws SQLException{ ps2.setInt(1, teacherId_1); ps2.setInt(2, teacherId_2); ResultSet rs = ps2.executeQuery();

ArrayList<Klass> common = new ArrayList<>();

while (rs.next()) { Klass klass = new Klass(rs.getInt("code"), rs.getString("subject")); common.add(klass); }

printCommon(common, teacherId_1, teacherId_2);}

Array list ofcommon classes.

Page 21: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

21

Managing Expectations

Estimation

How long will tasks take, or how many resources will they consume.

Should be an unbiased, analytical process. Goal is accuracy, not to seek a particular result.

Project planning

A biased, goal-seeking process. Goal is to achieve specific outcomes.

_

Page 22: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

22

Managing Expectations, cont’d

Estimates form the foundation for plans.

But plans don’t have to be the same as estimates.

Combining estimating and planning activities leads to bad estimates and poor plans.

A large gap between estimates and planning targets results in a high risk project._

Page 23: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

23

Estimates, Targets, and Commitments

An all-too-familiar scenario:

Product manager: We need to demo these features at a trade show in 3 months. [target] How long will it take?

Project lead: I estimate it will us take 5 months. Manager: Wrong answer! Try again. Lead: OK, in 3 months, we can have the highest

priority features done. [commitment]

Moral: When you’re asked for an estimate, determine whether you’re really being told to make a commitment to meet a target.

Page 24: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

24

Primary Purpose of Software Estimation

Determine whether a project’s targets are realistic enough to allow the project to be controlled to meet them.

Good estimates are usually possible if the initial targets and the initial estimates are within 20% of each other._

Page 25: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

25

“Good” Estimates

Estimates don’t need to be perfectly accurate as much as they need to be useful.

“A good estimate is an estimate that provides a clear enough view of the project reality to allow the project leadership to make good decisions about how to control the project to hit its targets.”

Steve McConnell, Software Estimation

Page 26: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

26

Time Unit Inflation of Estimates

Time unit inflation:hours → days → weeks → months → years

“It should take me two hours to do this.” Reality: It will take two days.

_

Page 27: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

27

Estimation Techniques

Complex mathematical formulas

Best for the very largest projects. Done by professional estimators.

History and analogy

How long did similar tasks take in the past?

Expert opinions

But do you have similar skills as the experts?

Page 28: CS 160: Software Engineering October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak mak

Computer Science Dept.Fall 2014: October 15

CS 160: Software Engineering© R. Mak

28

Estimation Techniques

Off-the-cuff “guesstimates”

Based on personal experience. The smaller the task,

the more accurate the estimate._