Software Modularity and Design - 1
Software Modularity and Design - 1
Summary Modularity
• Software Modularity: Benefits and Principles
• Object-Oriented (OO) Design • Constructing systems is a complex task
• Features of Good OO Design
• Software Maintenance Activities • Systems are designed and constructed such
• Design Defects that they consist of smaller, independently
• Refactoring manageable subsystems.
1
6/26/2009
2
6/26/2009
3
6/26/2009
4
6/26/2009
Encapsulation
• How many people can build an alarm clock?
• How many people know what an alarm clock
is?
Features of Good Object-Oriented • Public Interface vs. Implementation
Design • All the data and associated behavior should be
encapsulated in a single class
• A class should expose its behavior through
public interfaces
5
6/26/2009
Cohesion
• Keep related data and behavior in one place
• Spin-off non-related information into
another class
Software Maintenance
• Class should capture only one key
abstraction
• Example …
21
6
6/26/2009
7
6/26/2009
8
6/26/2009
An Example
Another Example
Class Student Class Course class Order {
{ { ...
boolean IsSameString(String s1, String s2){
String reg_no; String student_name; if(s1==s2) return true;
String course_name; Time time; if(s1==null) return false;
int age; } return(s1.equals(s2));
}
Course [ ] _courses; }
}
class Mail {
Class Student
...
{ Class Course static boolean IsSameString(String s1, String s2) {
String reg_no; { if (s1 == s2)
String student_name; String course_name; return true;
if (s1 == null)
int age; Time time; return false;
Course [ ] _courses; } return (s1.equals(s2));
}
}
}
9
6/26/2009
10
6/26/2009
11
6/26/2009
Benefits of Refactoring
• Ease of making changes: no ripple effects
• Code Reuse
• Distribution of responsibilities
12