06 ClassDesign
06 ClassDesign
Design Classes
ITSS SOFTWARE DEVELOPMENT/SOFTWARE DESIGN AND CONSTRUCTION
Project Specific
6. CLASS DESIGN Guidelines
Supplementary
Specifications
Analysis Classes
Some slides extracted from IBM coursewares
1 2
2. Define Operations/Methods
3. Define Relationships Between Classes <<control>>
<<subsystem>>
Subsystem
4. Define States
<<entity>>
5. Define Attributes
6. Class Diagram
<<boundary>>
<<subsystem>>
Subsystem
Many-to-Many Mapping
3 4
1
6
5 6
7 8
How Many Classes Are Needed? Strategies for Designing Boundary Classes
• Many, simple classes means that each class
• Encapsulates less of the overall system intelligence • User interface (UI) boundary classes
• Is more reusable • What user interface development tools will be used?
• How much of the interface can be created by the
• Is easier to implement
development tool?
• A few, complex classes means that each class • External system interface boundary classes
• Encapsulates a large portion of the overall system • Usually model as subsystem
intelligence
• Is less likely to be reusable MainWindow SubWindow
7 8
2
9 10
Strategies for Designing Entity Classes Strategies for Designing Control Classes
• Entity objects are often passive and persistent • What happens to Control Classes?
• Performance requirements may force some re-factoring • Are they really needed?
Analysis Design • Should they be split?
<< Entity >> FatClass
FatClass - privateAttr • How do you decide?
- privateAttr
- commonlyUsedAttr1 + getCommonlyUsedAttr1()
- commonlyUsedAttr2 + getCommonlyUsedAttr2() • Complexity
- rarelyUsed1 + getRarelyUsedAtt1()
- rarelyUsed2 + getRarelyUsedAtt2() • Change probability
1 0..1
• Distribution and performance
FatClassDataHelper FatClassLazyDataHelper • Transaction management
- commonlyUsedAttr1 - rarelyUsedAttr1
- commonlyUsedAttr2 - rarelyUsedAttr2
9 10
• A general purpose mechanism for organizing elements and services the system uses
Package B
into groups
Package A
• A model element which can contain other model
elements
Package
Name
11 12
3
Packaging Tips: Boundary Classes Packaging Tips:
If it is likely the system interface If it is unlikely the system interface
Functionally Related Classes
will undergo considerable changes will undergo considerable changes • Criteria for determining if classes are functionally
related:
• Changes in one class' behavior and/or structure
necessitate changes in another class
• Removal of one class impacts the other class
• Two objects interact with a large number of messages
or have a complex intercommunication
• A boundary class can be functionally related to a
particular entity class if the function of the boundary
class is to present the entity class
• Two classes interact with, or are affected by changes in
Boundary classes placed in Boundary classes packaged
separate packages with functionally related classes the same actor
13 14
OO Principle: Encapsulation
15 16
4
Package Coupling: Tips
Example: Registration Package
• Packages should not be A B
cross-coupled
X MainStudentForm MainRegistrarForm
1 1
Lower
layers Layer B 1
1 1
<<control>> <<control>>
RegistrationController CloseRegistrationController
• In general, dependencies
C
should not skip layers
X = Coupling violation
17 18
primaryCourses alternateCourses
0..2
<<entity>> 0..4
<<entity>> <<entity>>
FulltimeStudent ParttimeStudent
PrimaryScheduleOfferingInfo <<entity>> instructor <<entity>> <<entity>> 0..*
Professor CourseOffering Course
0..*
0..1 0..* 0..* 1
Prerequisites
0..*
1
CourseOfferingList
19 20
5
22
21 22
23 24
23 24
6
25 26
Program documentation
/** Guidelines: Designing Operation Signatures
* Parse XML data into a DOM representation, taking local resources and
Schemas into account.
* @param inputData a string representation of the XML data to be parsed. • Whendesigning operation signatures, consider if
* @param validating whether to Schema-validate the XML data
* @return the DOM document resulting from the parse parameters are:
* @throws ParserConfigurationException if no parser could be created
* @throws SAXException if there was a parse error
• Passed by value or by reference
* @throws IOException if there was a problem reading from the string • Changed by the operation
*/
public static Document parseDocument(String inputData, boolean validating) • Optional
throws ParserConfigurationException, SAXException, IOException {
//Change to UnicodeReader for utf-8 • Set to default values
}
...
• In valid parameter ranges
• The fewer the parameters, the better
• Pass objects instead of “data bits”
25 26
27
27 28
7
29 30
29 30
31 32
31 32
8
33 34
• Realization
33 34
35 36
35 36
9
37 38
37 38
39 40
Prerequisites
39 40
10
41 42
41 42
Java
What Does Multiplicity Mean? implementation
• Multiplicity answers two questions:
//InsuranceCompany.java file
• Is the association mandatory or optional? public class InsuranceCompany
{
• What is the minimum and maximum number of // Many multiplicity can be implemented using Collection
private List<InsuranceContract> contracts;
instances that can be linked to one instance?
/* Methods */
}
<<entity>> <<entity>>
0..* 1 // InsuranceContract.java file
CourseInfo. Subject
public class InsuranceContract
0..* {
private InsuranceCompany refers_to;
Prerequisites 0..3
/* Methods */
}
43 44
11
45 46
45 46
47
• The part may be removed (by the whole) before the whole is
removed.
Whole Part
48
47 48
12
49 @Nguyễn Thị Thu Trang, [email protected] 50
1 0..2,4
49 50
51 52
13
53 54
53 54
55 56
55 56
14
57 58
57 58
59 60
59 60
15
61 62
61 62
63 64
Descendents
63 64
16
65 66
65 66
67 68
67 68
17
69 70
Events: addLecturer,
removeLecturer Unassigned
removeLecturer addLecturer
Assigned
69 70
71 72
addLecturer Canceled
cancel
do/ Send cancellation notices
• Do cancel
removeLecturer 3] [ numStudents = 30 ]
el
• Ongoing execution canc ts <
den Full
Stu
num
n[
tio
StateB StateC stra
egi 30 ]
R nts =
• Exit Do/anActivity Exit/someAction addStudent /
clo
se
[ num
Stude
closeRegistration [ has Professor assigned ]
numStudents = numStudents + 1
• Executed when the state
Assigned closeRegistration[ numStudents >= 3 ] Committed
is exited do/ Generate class roster
71 72
18
73 74
Which Objects Have Significant State? How Do State Machines Map to the Rest of the Model?
[numStudents<10] [numStudents>=10]
73 74
75 76
75 76
19
77 78
77 78
79 80
79 80
20
81 82
81 82
83 84
83 84
21
85
85 86
87 88
22
90
89 90
91 92
Program documentation
Class design /**
* Parse XML data into a DOM representation, taking local resources and
Schemas into account.
• Attribute design * @param inputData a string representation of the XML data to be parsed.
* @param validating whether to Schema-validate the XML data
• Type, description * @return the DOM document resulting from the parse
* @throws ParserConfigurationException if no parser could be created
• Operation design * @throws SAXException if there was a parse error
* @throws IOException if there was a problem reading from the string
• Operation Signature */
• Purpose/description of operation public static Document parseDocument(String inputData, boolean validating)
throws ParserConfigurationException, SAXException, IOException {
• Purpose /description of each parameter //Change to UnicodeReader for utf-8
...
• Description of return value }
• Error/Exception (when)
• Method design
• Special algorithm
• How to use parameters
91 92
23