COMP 304B Object-Oriented Software Design -- Assignment 2

COMP 304B Object-Oriented Software Design - Assignment 2

Practical information




In this assignment, you will use UML Class Diagrams, UML Sequence Diagrams, Regular Expressions, and State Automata to design and verify a communication protocol of a client-server system. The client part of the system has a user interface from which the user can input messages and send them. The client also receives messages from a chat room which it has subscribed to. A chat room is a server. It receives messages from its clients and broadcasts these messages to subscribed clients. A chat room can have 0 or more clients. A client can be connected to 0 or more chat rooms at any time. In your design, there will be no actual interaction with the human user. Rather, the clients simulate human operations (i.e., sending connection requests and sending messages) in a random way.

The assignment is divided into two major parts.

Warning: Both parts of the assignment will require considerable effort. Expect part 2 to take at least as much time as part 1, and schedule your work accordingly. Given that there are two weeks available, a good schedule would be to complete part 1 the first week, and part 2 the second week.

Part 1

The following is a textual description of a simple protocol:
Interaction behaviour to be verified (use cases):
  1. When a client sends a connection request to a chat room, the chat room immediately responds by printing to the output.
  2. On receiving a connection request, the chat room immediately makes a decision whether to accept the client or reject it.
  3. When a chat room accepts a client, the client immediately receives the acceptance and dumps to the output.
  4. When a chat room rejects a client, the client also immediately dumps the rejection.
  5. When a client sends a message, the chat room immediately receives it and prints the message to the output.
  6. When a chat room receives a message, it broadcasts it to all connected clients except the sender.
  7. The sender cannot receive its own message after it sends it.
Six tasks you need to finish step by step:
  1. Design the dynamic interaction behaviour in UML Sequence Diagrams for ONLY use cases 2 and 7 in BoUML;
  2. Write regular expressions (refer to the format of the given output trace) for verifying the above use cases (in this assignment, you only need to verify TWO use cases: use case 2 and use case 7); the following is an example:
    Regular expression pattern for rule 1:
    ##[^\n]*\n\(CL (\d+)\) RS (\d+)\.\n##[^\n]*\n\(CR \2\) RR \1\.\n
    The following output will match the above pattern (multiple lines!):
    ## (Client 2) A connection request is sent to chat room 1.
    (CL 2) RS 1.
    ## (Chat room 1) Received connection request from client 2.
    (CR 1) RR 2.
    Clarification: the above uses a Regular Expression notation commonly used in UNIX Regular Expressions (as used in the stream editor sed for example) which differs from the examples given in class. In addition to the slightly different notation, the expressive power of these Regular Expressions is also higher as it allows for memory of matched expressions making the patterns context dependent.
    • [eE] stands for e or E.
    • [a-z] stands for one of the characters in the range a to z.
    • ^ means "match at the beginning of a line/string".
    • $ means "match at the end of the line/string".
    • [^x] means not x, so ##[^\n]*\n matches a comment line: ## followed by 0 or more non-newline characters, followed by newline.
    • . matches any single character.
    • X? matches 0 or 1 repititions of X.
    • X* matches 0 or more repititions of X.
    • X+ matches 1 or more repititions of X.
    • \ is used to escape meta-characters such as (. If you want to match the character (, you need the pattern \(.
    • The ( and ) meta-characters are used to memorize a match for later use. They can be used around arbitrarily complex patterns. The first (\d+) in the above regular expression matches any non-empty sequence of digits (assuming d has been defined elsewhere as [0-9]). The matched pattern is memorized and can be referred to later by using \1. Following matched bracketed patterns are referred to by \2, \3, etc. Note that you will need to encode powerful features such as this one by adding appropriate actions (side-effects) to your automaton encoding the regular expression. This can easily be done by storing a matched pattern in a variable and later referring to it again.
    You are welcome to use different variant notations (such as the one used in the Python Regular Expression module) as long as you explain your notation.
  3. Design a FSA which encodes the regular expressions for verification in BoUML;
  4. Implement this FSA for verification in the provided code framework (see;
  5. Run this FSA implementation (which in turn implements the Regular Expressions which in turn encode the checking of interaction behaviour use cases which were modelled as Sequence Diagrams) on the given output trace to verify the specification.
  6. There is an intentional bug in the implementation ( which makes it fail to satisfy the system specification. You need to figure it out by verifying the output trace with your FSA implementation, and fix it (just one line).
Starting Point:

Part 2

You must use BoUML in synthesizing your own implementation. A guide has been written to help you use BoUML. The program can be tricky, and the guide will come in useful.
  1. First, you will need to create your UML class diagram of the system. Do this in BoUML.
  2. Analyze the requirements, and decide what classes you will need in your implementation. Create these classes in your diagram.
  3. Your classes will need attributes and operations. Work from the requirements to decide what is needed. Using the output from the existing implementation can be helpful.
  4. Start filling in the bodies of the methods. Once again, the requirements and to a lesser extent the existing (ugly) implementation will be helpful.
  5. Generate code. BoUML uses a template for classes, attributes, procedures, and associations. This template allows BoUML to generate code that uses the properties you have defined in your UML diagram. Operations are completed using the body you entered. An error in the diagram will appear in the code, and thus you will need to carefully examine your generated code. You may need to edit some of the templates that BoUML uses to generate code for specific procedures, associations, properties, etc.--you should not assume that BoUML will always generate correct code! This will probably take many iterations before your code is runnable, and more iterations before you are satisfied with the result. Likely, it will be the most time consuming step in Part 2. Note that the benefit of this approach is that once one has set up the proper templates, any modification of the design allows instant code synthesis. So, no need to go into the code and edit.
  6. Continue working with code generation until you are comfortable that the code generated by BoUML is correct. While editing generated code may be a convenient method to debug, it MUST be the case that the code you finally use is generated with a single click from your UML diagram in BoUML.
  7. Run your program and create a trace.
  8. Use your existing testing framework (from Part 1) to verify that your code is correct. Repeat the test cases given in part 1. If a test fails, you must go back into your UML diagram, correct the error, and repeat the test until your implementation satisfies all requirements.
  9. Submit your BoUML project, your code, and test results in the format described above.


Regular Expression patterns recognition
Sample BoUML Project

Chris Dragert and Hans Vangheluwe. Winter Term 2009.