This site is from a past semester! The current version will be here when the new semester starts.
CS2103/T 2020 Aug-Dec
  • Full Timeline
  • Week 1 [Mon, Aug 10th]
  • Week 2 [Fri, Aug 14th]
  • Week 3 [Fri, Aug 21st]
  • Week 4 [Fri, Aug 28th]
  • Week 5 [Fri, Sep 4th]
  • Week 6 [Fri, Sep 11th]
  • Week 7 [Fri, Sep 18th]
  • Week 8 [Fri, Oct 2nd]
  • Week 9 [Fri, Oct 9th]
  • Week 10 [Fri, Oct 16th]
  • Week 11 [Fri, Oct 23rd]
  • Week 12 [Fri, Oct 30th]
  • Week 13 [Fri, Nov 6th]
  • Textbook
  • Admin Info
  • Dashboards
  •  Individual Project (iP):
  • Individual Project Info
  • iP Upstream Repo
  • iP Showcase
  • iP Code Dashboard
  • iP Progress Dashboard

  •  Team Project (tP):
  • Team Project Info
  • Addressbook-level3
  • Team List
  • tP Code Dashboard
  • tP Progress Dashboard
  • Report Bugs
  • Forum
  • Gitter (Chat)
  • Instructors
  • Announcements
  • Files
  • Tutorial Schedule
  • Java Coding Standard
  • Git Conventions
  • Forum Activities Dashboard
  • Participation Dashboard
  • Week 8 [Fri, Oct 2nd] - Tutorial

    [Image source: this article]

    Hand-drawing diagrams on a white-board and on paper is an important practical skill (e.g., for technical interviews, project discussions). It's possible that the diagrams you draw in your first few attempts to look amateurish, messy, and hard to read, and the drawing itself will take a long time. With more practice, you will be able to draw such diagrams quicker (e.g., draw as you explain verbally your design), with less need for corrections, and the diagrams will look more professional too.

    That is why we have structured these tutorials to get everyone to practice this skill so that your first few (not-so-good) diagram drawing experiences happen in the tutorial, not in an interview or during your internship.

    Note the following:

    • Draw on paper or on a whiteboard or use a free-hand drawing software (e.g., Bamboo paper). If latter, do not use UML software or predefined shapes.
    • For the same reason, don't use rulers.
    • When the tutor asks you to, take a screenshot or a photo of the drawing and post in the tutorial workspace document.
    • There are mobile apps (example) that can take a photo of a document and and convert it to a high-quality scan.

    1 Exercise: draw a class diagram and an object diagram

    Question adapted from past exam paper.

    1. before the tutorial Do the following exercise, by hand-drawing the answer.
      Use the following layout:

    Consider the code below:

    public interface Billable {
    void bill();
    }
    public abstract class Item
    implements Billable {
    public abstract void print();
    }
    public class StockItem extends Item {
    private Review review;
    private String name;

    public StockItem(
    String name, Rating rating) {

    this.name = name;
    this.review = new Review(rating);
    }

    @Override
    public void print() {
    //...
    }

    @Override
    public void bill() {
    //...
    }
    }
    public enum Rating {
    GOOD, OK, POOR
    }
    public class Review {
    private final Rating rating;

    public Review(Rating rating) {
    this.rating = rating;
    }
    }
    import java.util.List;

    public class Inventory {
    private List<Item> items;

    public int getItemCount() {
    return items.size();
    }

    public void generateBill(Billable b) {
    // ...
    }

    public void add(Item s) {
    items.add(s);
    }
    }

    (a) Draw a class diagram to represent the code. Show all attributes, methods, associations, navigabilities, visibilities, known multiplicities, and association roles. Show associations as lines.
    (b) Draw an object diagram to represent the situation where the inventory has one item named spanner and a review of POOR rating
    i.e., new Inventory().add(new StockItem("spanner", new Review(Rating.POOR))).

    1. during the tutorial
      • Paste the diagram (take a photo if you drew on paper) in the tutorial workspace document.
      • Discuss answers as guided by the tutor.

    2 Exercise: draw a sequence diagram

    1. before the tutorial

    (a) Do the following exercise similar to the previous one.

    Consider the code below:

    class Person {
    Tag tag;
    String name;

    Person(String personName, String tagName) {
    name = personName;
    tag = new Tag(tagName);
    }
    }
    class Tag {
    Tag(String value) {
    // ...
    }
    }

    class PersonList {
    void addPerson(Person p) {
    // ...
    }
    }

    Draw a sequence diagram to illustrate the object interactions that happen in the code snippet below:

    PersonList personList = new PersonList();
    while (hasRoom) {
    Person p = new Person("Adam", "friend");
    personList.addPerson(p);
    }

    (b) How would you update the diagram if the PersonList class was updated as follows?

    class PersonList{
    void addPerson(Person p){
    add(p);
    }

    void add(Person p){
    //...
    }
    }
    1. during the tutorial:
    • As before, paste the diagramin the tutorial workspace document, and take part in the follow up discussion, as guided by the tutor.