Questions

advertisement
Some Review Questions
March 31, 2006
1. Consider a course at university that has a certain capacity; for example the capacity
for 92.3913 is set at 25 students. At any point in time, a course is considered to be in
some state, such as open, full, active, cancelled.
 The initial state for the course is open; the course is initially open for
registrations.
 When a student registers for the course the number registered is incremented by 1.
As long as the number registered is less than capacity the course is still open for
registrations, but if the number registered equals the course capacity then the
course is considered full.
 No one can register for a course that is full. Students can only register for courses
that are open.
 When the term begins a full course becomes active.
 A student is allowed to register for a course that is active as long as the number
registered does not exceed the capacity for the course and if we are within the first
2 weeks of classes.
 When the term begins an open course is cancelled if the course has less than ten
students, otherwise it becomes active.
a) Model the course and its states as a statechart diagram.
b) Create a class model for the course and its states using the State pattern.
c) To ensure a robust system, each class (state) is able to respond to any incoming
message. For each class indicate the incoming messages that will be treated as
errors if they are ever received.
d) Indicate, to the extent possible, the behaviour (sequence diagram) when 92.3913
receives a registration for student Mr. X.
i) Assume when this happens that the course is open with only 20 students
registered.
ii) Assume when this happens that the course is open with 24 students registered
(i.e. Mr. X is number 25!)
2. A certain class has a complicated set of methods capable of doing more than you
need; this class is named DisplayManager. Two of these methods are draw(a,b,c) and
resize(x,y,z). Suppose you have an adapter class ADAP that maps print(a,b) to
draw(a,b,c) and stretch(x,y) to resize(x,y,z). ADAP is implemented as a singleton.
Suppose there is an object named myObject which is an instance of Client, and
myObject needs to send a print message and a stretch message. Show all messages
that will be sent if the instance of the adapter does not currently exist.
1
3. Suppose Facade is the name of a class implemented with the Singleton pattern, and
suppose we use Façade to communicate with a database system. Some client object
will send messages to a Façade, the Façade in turn sends messages on to the database,
the database returns results to the Façade and the Façade returns results to our client.
In particular, we use a Façade for database transactions that begin with startTrans()
and end with either commitTrans() or rollbackTrans(). Between these two messages
we send other database commands such as read(), update(), delete(), and insert(). For
instance, a sample transaction is:
startTrans()
read(a)
update(a)
read(b)
update(b)
rollbackTrans()
For our sample transaction, show the messages sent excluding any to the database. Use
one sequence diagram to show all messages that could be sent. Your diagram provides
for two alternate cases as is possible with Singleton.
2
4. Consider the hierarchy below. It represents a certain drawing named D1 that is
composed according to the Composite pattern. A drawing can be complex – made up
of other drawings. Lines, rectangles, circles and stars are basic components used to
make complex drawings. Lines, rectangles, circles and stars are not composed of
other things. Each class must implement draw(), and count(). Count() is used to
determine the number of nodes in a subtree; draw() is used to ask a component to
draw itself. If the composite pattern is used, show
a. The class model, and show the relevant interfaces, classes, attributes,
methods, associations (including inheritance associations), multiplicities and
navigability.
b. The complete interaction diagram beginning with D1 receiving the count()
message.
c. How would the interaction diagram differ to represent the collaboration when
D1 receives the draw() message?
D1: drawing
L1: line
D2: drawing
R1:rectangle
C1: circle
S1: star
D3: drawing
R2: rectangle
C2: circle
*************************** end *****************************************
3
Download