Slide 1

Slide 1 text

Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.info o ffi ce: 14 -227 CSC 307 Introduction to Software Engineering Lecture 08. Code Review

Slide 2

Slide 2 text

Good Code vs Bad Code 2

Slide 3

Slide 3 text

Clean Your Code! • M a nuf a cturing vs. Cr a fting Softw a re • Code is me a nt for hum a n consumption, a nd it’s me a nt for computer consumption. • Cre a ting softw a re together but not scr a mbled 3

Slide 4

Slide 4 text

Not Everything that Can be … Should be … 4

Slide 5

Slide 5 text

Clean Code • Write e ff icient code but prioritize re a d a bility a nd m a int a in a bility. • Optimize perform a nce-critic a l sections only when necess a ry. 5

Slide 6

Slide 6 text

Clean Code :: Readability (Easy to read to others) • Single Responsibility Principle (SRP) • Style a nd Comments • Do not Repe a t Yourselves (DRY) • Keep It Simple (KIS) • Dependency Injection (DI) • Error H a ndling 6

Slide 7

Slide 7 text

Single Responsibility • E a ch cl a ss or function should h a ve one, a nd only one, job. • Keep functions focused on a single t a sk. • Bre a k down your code into sm a ller, reus a ble modules or functions. • Ensure e a ch module or function h a s a cle a r, well-de f ined purpose. • 7

Slide 8

Slide 8 text

Don't Repeat Yourself (DRY) • Avoid code duplic a tion by a bstr a cting common function a lity. • Use functions or cl a sses to enc a psul a te repe a ted jobs. 8

Slide 9

Slide 9 text

Keep It Simple (KIS) • Aim for simplicity in your design a nd implement a tion. • Avoid unnecess a ry complexity or over-engineering. 9

Slide 10

Slide 10 text

Dependency Injection • An object’s dependencies (other objects it relies on) a re provided extern a lly r a ther th a n cre a ted intern a lly by the object itself. • Constructor injection: Dependencies a re p a ssed vi a the cl a ss constructor. • Setter injection: Dependencies a re provided through setter methods. • M a ke components more a ccessible to sw a p or extend without modifying the dependent cl a ss. 10

Slide 11

Slide 11 text

Readability 11

Slide 12

Slide 12 text

Agile in Action 12

Slide 13

Slide 13 text

Daily Scrum

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

Daily Scrum Module 01 Projects

Slide 17

Slide 17 text

J. P. O. L. O. S. Module Projects

Slide 18

Slide 18 text

Tip #1 18 Do not create a global variable Blackboard

Slide 19

Slide 19 text

Tip #2 19 If you are to receive a parameter Use the parent class instead of a child. Example: JFrame vs Main

Slide 20

Slide 20 text

Tip #3 20 EditProject<> vs NewProject<> It is 4 classes instead of 2 DRY :: Do not Repeat Yourselves

Slide 21

Slide 21 text

KIS 21 KIS - Keep it Simple Do we need this?

Slide 22

Slide 22 text

Daily Scrum Module 02 Data Objects

Slide 23

Slide 23 text

J. G. O. S. F. R. J. G. A. B. C. H. DRY :: Do not Repeat Yourselves

Slide 24

Slide 24 text

Ownership 24 Make sure your clients (dependents) are satisfied

Slide 25

Slide 25 text

Keep It Simple

Slide 26

Slide 26 text

Daily Scrum Module 03 Stories

Slide 27

Slide 27 text

N. G. L. G. J. G. Module Stories

Slide 28

Slide 28 text

Fix 28 BacklogStoryRenderer Review the Error about Incompatibility (class Story)

Slide 29

Slide 29 text

BacklogWindow.java 29 Clean your Code

Slide 30

Slide 30 text

NewStoryPanel.java 30 What about a method with more than 200 Lines?

Slide 31

Slide 31 text

Daily Scrum Module 04 Tasks

Slide 32

Slide 32 text

C. H. K. M. A. B. Module T a sks F. R.

Slide 33

Slide 33 text

CreateTaskPanel.java 33 What about a method with more than ~120 Lines?

Slide 34

Slide 34 text

CreateTaskPanel.java :: ~120 LOC 34 Can be done but Should be?

Slide 35

Slide 35 text

Blackboard as Attribute? 35

Slide 36

Slide 36 text

CreateTaskPanel.java 36 Blackboard as parameter?

Slide 37

Slide 37 text

MoveTasks.java 37 Do not use verbs as names for classes! Refactor MoveTasks to be Panel instead of Frame

Slide 38

Slide 38 text

Clean?

Slide 39

Slide 39 text

Daily Scrum Module 04 Main

Slide 40

Slide 40 text

I. P. D. X. Module M a in

Slide 41

Slide 41 text

Dependency Injections 41 Pass as a parameter Sprint or Stories or Project, so you do not need to pass a Full Blackboard for testing

Slide 42

Slide 42 text

Test Folder 42

Slide 43

Slide 43 text

Test Folder 43

Slide 44

Slide 44 text

Lab. Code Review

Slide 45

Slide 45 text

Lab 45 https://classroom.github.com/a/LXc5UHtr

Slide 46

Slide 46 text

Step 1 46 Fix your Code

Slide 47

Slide 47 text

Step 2 • Cre a te a Test Cl a ss for your very own Story (in the Test Folder) • No m a in methods inside of cl a sses th a t should not h a ve them, i.e., m a in methods for testing your p a rt goes on the test folder • Only one single m a in method in the j a v a source folder • The m a in method st a rt with “Show the Project P a ge” 47

Slide 48

Slide 48 text

Step 3. Who Calls Who? 48

Slide 49

Slide 49 text

Step 4 49 Draft a Class Diagram

Slide 50

Slide 50 text

Questions 50

Slide 51

Slide 51 text

CSC 307 Introduction to Software Engineering Javier Gonzalez-Sanchez, Ph.D. [email protected] Winter 2026 Copyright. These slides can only be used as study material for the class CSC307 at Cal Poly. They cannot be distributed or used for another purpose.