01 Simple Architectures - Solutions
01 Simple Architectures - Solutions
01 Simple Architectures - Solutions
6CCS3SAD/7CCSMDAS
Software Architecture & Design
ILoyaltyProgram
IHolidayRes
Holiday
Reservation
Session
ICarRes
CarRes
HotelRes
IHotelRes
CreditCardBilling
IBilling
IAirRes
AirRes
Answer: A correct answer is any UML 2 interface description that is cohesive and clearly
performs the functions of the component. Methods are clearly related to each other and to the
purpose of the component. 3 or 4 methods per interface is realistic. If this were an exam, half
marks would be obtained for getting the UML2 interface written; full marks for making an attempt
to describe the semantics of the methods in the interface (in English).
2.
IDiskUtil
ExamMarking
<<interface>>
IExam
+InputGrade(ID:int,mark:float,code:SubjectCode)
+CalculateOverallAverage():float
+CalculateOverallDistribution(code:SubjectCode):Distribution
+Standardize():void
+ViewMark(ID:int,code:SubjectCode):float
+CalculateStudentAverage(ID : int):float
+FixNiceSnack()
IExam interface semantics:
InputGrade takes in the final grade for a student for a subject. ID is the student's ID, mark
is the student's grade and code is the code of the subject being graded.
CalculateOverallAverage computes the overall average grade for all students in all
subjects this is returned as a floating point.
CalculateDistribution computes the overall mark distribution for a subject this is
returned as an element of the Distribution data structure. code is the code of the
subject.
Standardize is a function that standardizes mark distributions for all subjects.
ViewMark retrieves the grade of a student this is returned as a float. ID is the student's
ID, code is the subject code.
CalculateStudentAverage computes the average grade for a particular student,
returning this as a float. ID is the student's ID.
FixNiceSnack orders a nice snack for Steffen.
<<interface>>
IDiskUtil
+storeList(fileName:string,grades:List)
+readList(fileName:string):List
+emailStudentTranscript(grades:List)
+emailWarning(grades:List)
+orderCoffee(strength:int)
+orderChocolate(type:ChocolateType)
IDiskUtil
storeList writes the list of grades to a file. fileName is the name of the file. grades is
the list of grades for all students in all subjects.
readList reads a list of grades for all students in all subjects from a file, returning them as
an element of the data structure List. fileName is the name of the file to be read from.
emailStudentTranscript emails a transcript of grades to each student mentioned in
the grades list. grades is the list of grades for all students in all subjects.
emailWarning emails threats of expulsion from the College to all students mentioned in
the grades list whose average falls below a certain point. grades is the list of grades for
all students in all subjects.
orderCoffee() utilizes the Departments automated telephony system and calls Caff
Nero to order Steffen his favourite espresso. strength is the number of espresso shots
required.
orderChocolate() uses the telephony system to order Steffen a bar of chocolate. type
is kind of chocolate required.
What is wrong with this component specification? Fix it, bearing in mind the discussion on what
makes a component from last weeks lecture. (Note there are several things that are obviously
wrong with this component, and several more subtle problems.) Use the space below to write
down your answers.
Answer: The interfaces are not cohesive.
1. IExam and IDiskUtil are about examination results and storing data, according to the
system description. The FixNiceSnack function of IExam and orderCoffee and
orderChocolate functions have nothing to do with the objective of the interfaces or
components they should be removed from these interfaces and put into different
interfaces. But even when put into different interfaces, they should also be removed from the
components, as they have nothing to do with the component functionality as a whole.
2. IExam can be split into two different interfaces to ensure better cohesion. InputGrade,
CalculateOverallAverage, CalculateDistribution, and Standardize methods
are functions to do with examination mark administration performed by teachers and
administrators, while ViewMark, and CalculateStudentAverage are functions to do with
individual student-oriented views on the system. A possible solution is to divide these two
sets of functions into two interfaces, IMarkAdmin, to do with administration, and
IStudentView, to do with providing views to students.
3. Similarly, sending marks and storing marks are two different kinds of functionality it would
be a better design to place storeList and readList in a new required interface
IDiskAdmin
and
put
emailStudentTranscript(grades:List)
and
emailWarning(grades:List) in a new required interface IEmail.
EmailChecker
This is a common consulting role: to work backwards from code to design, and then (possibly) to
aid in making improvements.
Look at the Java code and draw a simple components-and-connector architectural diagram in
UML2.
Remember to abstract away parts of the code that are not architecturally relevant. In the lectures
we saw how abstract components can be implemented as classes. However, always remember
that not all classes correspond to components!
You dont need to understand the code in much detail. You are a senior consultant, and havent
actually written a program in yearsand that was written in Smalltalk. The main thing is to focus
on the coarse grain aspects of the code, ignoring fine grain stuff like algorithms, method content
and data structures as much as you can.
The code begins on the next page. Use the space below to draw your architecture diagram.
Answer: This is a trick question most of the code is not important from an architectural
perspective.
The Invitation class references an object of type Transportable, and the code instantiates
this reference with a Transport object. The architecture diagram simply consists of
1. An Invitation component. The provided interface is an interface that has all the public
methods of the Invitation class. You can give this interface any name you like. For
example, you could define an interface IInvitation with one operation
public void sendInvitation().
The required interface is the Transportable interface, written in UML2 instead of Java.
2. A Transport component. The provided interface is the Transportable interface,
written in UML2 instead of Java.
3. A connection between the two components provided and required interfaces.
The other classes have to do with data structures (e.g., the Address class) or starting up the
system (e.g., the System class). These things are not coarse grain and so do not correspond to
components.