This site is from a past semester! The current version will be here when the new semester starts.
CS2103/T 2020 Jan-Apr
  • Full Timeline
  • Week 1 [Jan 13]
  • Week 2 [Jan 20]
  • Week 3 [Jan 27]
  • Week 4 [Feb 3]
  • Week 5 [Feb 10]
  • Week 6 [Feb 17]
  • Week 7 [Mar 2]
  • Week 8 [Mar 9]
  • Week 9 [Mar 16]
  • Week 10 [Mar 23]
  • Week 11 [Mar 30]
  • Week 12 [Apr 6]
  • Week 13 [Apr 13]
  • Textbook
  • Admin Info
  • Report Bugs
  • Forum
  • Instructors
  • Announcements
  • File Submissions
  • Tutorial Schedule
  • Java Coding Standard
  • Participation Marks List

  •  Individual Project (iP):
  • Individual Project Info
  • Duke Upstream Repo
  • iP Code Dashboard
  • iP Showcase

  •  Team Project (tP):
  • Team Project Info
  • Team IDs
  • Addressbook-level3
  • Addressbook-level 1,2,4
  • tP Code Dashboard
  • tP Showcase
  • Week 6 [Feb 17] - Topics

    • [W6.1] Modeling: Sequence Diagrams
    • [W6.1a] Design → Modelling → Modelling Behaviors Sequence Diagrams - Basic

    • [W6.1b] Design → Modelling → Modelling Behaviors Sequence Diagrams - Intermediate

    • [W6.1c] Tools → UML → Sequence Diagrams → Reference Frames

    • [W6.1d] Tools → UML → Sequence Diagrams → Parallel Paths

    • [W6.2] Architecture Diagrams
    • [W6.2a] Design → Architecture → Introduction → What

    • [W6.2b] Design → Architecture → Architecture Diagrams → Reading

    • [W6.2c] Design → Introduction → Multi-Level Design

    • [W6.3] IDEs: Basic Features
    • [W6.3a] Implementation → IDEs → Debugging → What

    • [W6.3b] Tools → Intellij IDEA → Debugging: Basic

    • [W6.3c] Tools → Intellij IDEA → Code Navigation

    • [W6.4a] Implementation → Error Handling → Logging → What

    • [W6.4b] Implementation → Error Handling → Logging → How

    • [W6.5] Documentation Tools

       Markdown

    • [W6.5a] Implementation → Documentation → Tools → Markdown → What : OPTIONAL

    • [W6.5b] Implementation → Documentation → Tools → Markdown → How : OPTIONAL

       AsciiDoc

    • [W6.5c] Implementation → Documentation → Tools → AsciiDoc → What


    [W6.1] Modeling: Sequence Diagrams

    W6.1a

    Design → Modelling → Modelling Behaviors Sequence Diagrams - Basic

    Can draw basic sequence diagrams

    Explain in your own words the interactions illustrated by this Sequence Diagram:

    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);
    }

    Find notation mistakes in the sequence diagram below:

    W6.1b

    Design → Modelling → Modelling Behaviors Sequence Diagrams - Intermediate

    Can draw intermediate-level sequence diagrams

    What’s going on here?

    • a. Logic object is executing a parallel thread.
    • b. Logic object is executing a loop.
    • c. Logic object is creating another Logic instance.
    • d. One of Logic object’s methods is calling another of its methods.
    • e. Minefield object is calling a method of Logic.

    (d)

    Explain the interactions depicted in this sequence diagram.

    First, the createParser() method of an existing ParserFactory object is called. Then, ...

    Draw a sequence diagram to represent this code snippet.

    if (isFirstPage) {
    new Quote().print();
    }

    The Quote class:

    class Quote{

    String q;

    Quote(){
    q = generate();
    }

    String generate(){
    // ...
    }

    void print(){
    System.out.println(q);
    }

    }
    • Show new Quote().print(); as two method calls.
    • As the created Quote object is not assigned to a variable, it can be considered as 'deleted' soon after its print() method is called.

    W6.1c

    Tools → UML → Sequence Diagrams → Reference Frames

    Can interpret sequence diagrams with reference frames

    UML uses ref frame to allow a segment of the interaction to be omitted and shown as a separate sequence diagram. Reference frames help us to break complicated sequence diagrams into multiple parts or simply to omit details we are not interested in showing.

    Notation:

    The details of the get minefield appearance interactions have been omitted from the diagram.

    Those details are shown in a separate sequence diagram given below.

    W6.1d

    Tools → UML → Sequence Diagrams → Parallel Paths

    Can interpret sequence diagrams with parallel paths

    UML uses par frames to indicate parallel paths.

    Notation:

    Logic is calling methods CloudServer#poll() and LocalServer#poll() in parallel.

    If you show parallel paths in a sequence diagram, the corresponding Java implementation is likely to be multi-threaded because a normal Java program cannot do multiple things at the same time.

    [W6.2] Architecture Diagrams

    W6.2a

    Design → Architecture → Introduction → What

    Can explain Software Architecture

    The software architecture of a program or computing system is the structure or structures of the system, which comprise software elements, the externally visible properties of those elements, and the relationships among them. Architecture is concerned with the public side of interfaces; private details of elements—details having to do solely with internal implementation—are not architectural. -- Software Architecture in Practice (2nd edition), Bass, Clements, and Kazman

    The software architecture shows the overall organization of the system and can be viewed as a very high-level design. It usually consists of a set of interacting components that fit together to achieve the required functionality. It should be a simple and technically viable structure that is well-understood and agreed-upon by everyone in the development team, and it forms the basis for the implementation.

    A possible architecture for a Minesweeper game

    Main components:

    • GUI: Graphical user interface
    • TextUi: Textual user interface
    • ATD: An automated test driver used for testing the game logic
    • Logic: computation and logic of the game
    • Store: storage and retrieval of game data (high scores etc.)

    The architecture is typically designed by the software architect, who provides the technical vision of the system and makes high-level (i.e. architecture-level) technical decisions about the project.

    Choose the correct statement

    • a. The architecture of a system should be simple enough for all team members to understand it.
    • b. The architecture is primarily a high-level design of the system.
    • c. The architecture is usually decided by the project manager.
    • d. The architecture can contain details private to a component.

    (a)(b)

    (c) Reason: Architecture is usually designed by the Architect

    (d) Reason:

    ... private details of elements—details having to do solely with internal implementation—are not architectural.

    W6.2b

    Design → Architecture → Architecture Diagrams → Reading

    Can interpret an architecture diagram

    Architecture diagrams are free-form diagrams. There is no universally adopted standard notation for architecture diagrams. Any symbol that reasonably describes the architecture may be used.

    W6.2c

    Design → Introduction → Multi-Level Design

    Can explain multi-level design

    In a smaller system, design of the entire system can be shown in one place.

    This class diagram of se-edu/addressbook-level2 depicts the design of the entire software.

    Design of bigger systems needs to be done/shown at multiple levels.

    This architecture diagram of se-edu/addressbook-level3 depicts the high-level design of the software.

    Here are examples of lower level designs of some components of the same software:

    [W6.3] IDEs: Basic Features

    W6.3a

    Implementation → IDEs → Debugging → What

    Can explain debugging

    Debugging is the process of discovering defects in the program. Here are some approaches to debugging:

    • Bad -- By inserting temporary print statements: This is an ad-hoc approach in which print statements are inserted in the program to print information relevant to debugging, such as variable values. e.g. Exiting process() method, x is 5.347. This approach is not recommended due to these reasons.
      • Incurs extra effort when inserting and removing the print statements.
      • These extraneous program modifications increases the risk of introducing errors into the program.
      • These print statements, if not removed promptly after the debugging, may even appear unexpectedly in the production version.
    • Bad -- By manually tracing through the code: Otherwise known as ‘eye-balling’, this approach doesn't have the cons of the previous approach, but it too is not recommended (other than as a 'quick try') due to these reasons:
      • It is difficult, time consuming, and error-prone technique.
      • If you didn't spot the error while writing code, you might not spot the error when reading code too.
    • Good -- Using a debugger: A debugger tool allows you to pause the execution, then step through one statement at a time while examining the internal state if necessary. Most IDEs come with an inbuilt debugger. This is the recommended approach for debugging.

    W6.3b

    Tools → Intellij IDEA → Debugging: Basic

    Can step through a program using a debugger

    This video (from LaunchCode) gives a pretty good explanation of how to use the Intellij IDEA debugger.

    W6.3c

    Tools → Intellij IDEA → Code Navigation

    Can navigate code effectively using IDE features

    Some useful navigation shortcuts:

    1. Quickly locate a file by name.
    2. Go to the definition of a method from where it is used.
    3. Go back to the previous location.
    4. View the documentation of a method from where the method is being used, without navigating to the method itself.
    5. Find where a method/field is being used.

    [W6.4] Logging

    W6.4a

    Implementation → Error Handling → Logging → What

    Can explain logging

    Logging is the deliberate recording of certain information during a program execution for future reference. Logs are typically written to a log file but it is also possible to log information in other ways e.g. into a database or a remote server.

    Logging can be useful for troubleshooting problems. A good logging system records some system information regularly. When bad things happen to a system e.g. an unanticipated failure, their associated log files may provide indications of what went wrong and action can then be taken to prevent it from happening again.

    A log file is like the flight data recorderblack box of an airplane; they don't prevent problems but they can be helpful in understanding what went wrong after the fact.

    Why is logging like having the 'black box' in an airplane?

    (a)

    W6.4b

    Implementation → Error Handling → Logging → How

    Can use logging

    Most programming environments come with logging systems that allow sophisticated forms of logging. They have features such as the ability to enable and disable logging easily or to change the logging how much information to recordintensity.

    This sample Java code uses Java’s default logging mechanism.

    First, import the relevant Java package:

    import java.util.logging.*;

    Next, create a Logger:

    private static Logger logger = Logger.getLogger("Foo");

    Now, you can use the Logger object to log information. Note the use of INFO, WARNING etc.logging level for each message. When running the code, the logging level can be set to WARNING so that log messages specified as INFO level (which is a lower level than WARNING) will not be written to the log file at all.

    // log a message at INFO level
    logger.log(Level.INFO, "going to start processing");
    //...
    processInput();
    if(error){
    //log a message at WARNING level
    logger.log(Level.WARNING, "processing error", ex);
    }
    //...
    logger.log(Level.INFO, "end of processing");

    Tutorials:

    • A video tutorial by SimplyCoded:

    Best Practices:

    [W6.5] Documentation Tools


    Markdown

    W6.5a : OPTIONAL

    Implementation → Documentation → Tools → Markdown → What

    Can explain Markdown

    Markdown is a lightweight markup language with plain text formatting syntax.

    W6.5b : OPTIONAL

    Implementation → Documentation → Tools → Markdown → How

    Can write documents in Markdown format


    AsciiDoc

    W6.5c

    Implementation → Documentation → Tools → AsciiDoc → What

    Can explain AsciiDoc

    AsciiDoc is similar to Markdown but has more powerful (but also more complex) syntax.