WIF3004 (Software Architecture and Design Paradigms)
Semester 2, Session 2019/2020
Tutorial 1
1. Draw an abstraction hierarchy from the following given information.
A collection is a group of any type of objects. Collections can be categorised
based on two aspects, namely, indexing or non-indexing of objects, and
duplication or non-duplication of objects. The four constructors used generally
in object-oriented databases, namely set, bag, list and multilist are considered
as collections. Sets and bags are non-indexed collections, while lists and
multilists are indexed collections. Bags and multilists allow duplicates while sets
and lists do not.
2. Cohesion and coupling give impact to the quality of a software design for which a
good design should be loosely coupled and highly cohesive.
a. Given the following code snippet:
class CalTaxRate {
float rate;
float rateForRegion() {
ProductTaxRate ptr = new ProductTaxRate();
rate = [Link];
}
}
class ProductTaxRate {
public float productRate;
public float adjustedProductRate;
public float getProductRate(String reg) {
productRate = new CalTaxRate().rateForRegion();
return adjustedProductRate;
}
}
i. Identify and locate the types of coupling it may have in the
abovementioned code. Give your comments and justification.
ii. How should the above-mentioned code be rectified and further
enhanced to minimize coupling and maximize cohesion? Provide a
complete loosely coupled code.
b. It is said the cohesion indicates the degree to which a class has a single,
well-focused purpose. As such the higher the cohesion, the better is the
software design.
Given the following code snippet:
class YearlyReport {
…
void connectToRDBMS() {
…
}
void generateYearlyReport() {
…
}
void saveToFile() {
…
}
void print() {
…
}
}
i. Why do you think that the above code does not provide a highly
cohesive class design?
ii. How can the above class design be improved to produce a highly
cohesion class design? Illustrate your answer by modifying the code,
and explain why you think that your answer provides a highly
cohesive class design.