Professional Documents
Culture Documents
2/3/18
John Roberts
2
Context
3
Context
• Focus on the data, not the tasks - the data is less likely to
change, unlike the tasks
3
4
Objected Oriented Programming & Design
Principles
• Software components
• Abstract Classes
• Naming
• Patterns
6
CRC Cards
Collaborators
Responsibility of Component List of other components this
component deals with (e.g. whose
services it uses)
What it does (Methods)
8 Note that class diagrams provide the same information as CRC cards; there
Class Diagrams are CASE (Computer Aided Software Engineering) tools for constructing class
• Note the cardinality (1, n) and the association (uses) diagrams (Rational Rose)
Class Class
1 n
Methods/Data Methods/Data
uses
Professor Student
1 n
giveExercise() doExercise()
teach
9
Overview
• CRC Cards
• Software components
• Abstract Classes
• Naming
• Patterns
9
10 Context: Encapsulation
Software Components
Student
coursesCompleted
State
coursesEnrolledIn
study()
Behavior
doExercise()
10
11
Cohesion
11
12
Coupling
12
13
Overview
• CRC Cards
• Software components
• Abstract Classes
• Naming
• Patterns
13
14 DRY, SRP
Localize Changes
14
15
16 C++ preprocessor directives and pragmas
Minimize or Isolate Hardware Dependencies
• Porting considerations
16
17 SRP
Reduce Coupling Between Components
17
18
Document Important Design Decisions
• the code
18
19
Overview
• CRC Cards
• Software components
• Interfaces vs.
Implementation
• Abstract Classes
• Naming
• Patterns
19
20
Interfaces vs. Implementation
• Why?
20
21
Interfaces vs. Implementation
21
22
Example
22
23
24
25 “the interface” includes other interfaces you have written, in your own project
Program to an Interface, not an Implementation
25
26
27
Overview
• CRC Cards
• Software components
• Abstract Classes
• Naming
• Patterns
27
28 Context: Inheritance
Abstract Class
28
29
Example
https://github.com/sfsu-csc-413-roberts/lecture-4
Note the use of @Overrides here! Gives us compiler check (and warning if it’s
4 }
5
6 public void sleep( int hours ) {
31
32
Abstract Class vs. Interface
32
33
Overview
• CRC Cards
• Software components
• Abstract Classes
• Naming
• Patterns
33
34 non native english speakers may not be able to parse your abbreviations!
Naming keep your fellow programmers in mind.
• Use pronounceable, intention revealing names
34
35
36
Naming
36
37
Naming
37
38
Naming
38
39
Overview
• CRC Cards
• Software components
• Abstract Classes
• Naming
• Patterns
39
40
Software Design Patterns
40
41
Why Study Patterns?
41
42
Why Study Patterns?
42
43 We’ll look at a few of these this semester
Software Design Patterns
43
44
Software Design Patterns