Week 6 [Sep 17]

Todo

Admin info to read:

Admin Appendix B (Policies) → Policy on suggested length for submissions

Policy on suggested length for submissions

We don't usually give a strict page limit for documents such as User Guide and the Developer Guide. You need to decide yourself how long the document should be based on the purpose and the intended audience. You can determine the level of details required based on the samples we provide.


Admin Appendix C (FAQs) → Why very narrow project scope?

Why very narrow project scope?

Defining your own unique project is more fun.

But, wider scope → more diverse projects → harder for us to go deep into your project. The collective know-how we (i.e., students and the teaching team) have built up about SE issues related to the project become shallow and stretched too thinly. It also affects fairness of grading.

That is why a strictly-defined project is more suitable for a first course in SE that focuses on nuts-and-bolts of SE. After learning those fundamentals, in higher level project modules you can focus more on the creative side of software projects without being dragged down by nuts-and-bolts SE issues (because you already know how to deal with them). However, we would like to allow some room for creativity too. That is why we let you build products that are slight variations of a given theme.

Also note: The freedom to do 'anything' is not a necessary condition for creativity. Do not mistake being different for being creative. In fact, the more constrained you are, the more you need creativity to stand out.


Admin Appendix C (FAQs) → Why project requirements are so vague?

Why project requirements are so vague?

"You tell me exactly what to do - I do that - you pay me (in grades)" is a model for contract work, not for learning. Being able to survive in imprecise, uncertain, volatile problem contexts is precisely what we are trying to teach you.

For example, the best way to communicate something often depends on what is being communicated. That is why we don't specify the precise content for project documents. Instead, we aim to refine project documents iteratively. We believe the learning experience will be richer if we let you decide the best way to present your project information rather than just following our instructions blindly. For example, in real-life projects you are rarely told which diagrams to draw; that is a decision you have to make yourself.


Outcomes

Design

W6.1 Can use intermediate-level class diagrams
W6.1a Can use UML notes

Tools → UML →

Notes

UML notes can augment UML diagrams with additional information. These notes can be shown connected to a particular element in the diagram or can be shown without a connection. The diagram below shows examples of both.

Example:


W6.1b Can specify constraints in UML diagrams

UML → Notes

Tools → UML →

Constraints

A constraint can be given inside a note, within curly braces. Natural language or a formal notation such as OCL (Object Constraint Language) may be used to specify constraints.

Example:


W6.1c Can show an association as an attribute

Tools → UML → Class Diagrams →

Associations as Attributes

An association can be shown as an attribute instead of a line.

Association multiplicities and the default value too can be shown as part of the attribute using the following notation. Both are optional.

name: type [multiplicity] = default value

The diagram below depicts a multi-player Square Game being played on a board comprising of 100 squares. Each of the squares may be occupied with any number of pieces, each belonging to a certain player.

A Piece may or may not be on a Square. Note how that association can be replaced by an isOn attribute of the Piece class. The isOn attribute can either be null or hold a reference to a Square object, matching the 0..1 multiplicity of the association it replaces. The default value is null.

The association that a Board has 100 Sqaures can be shown in either of these two ways:


W6.1d Can use intermediate-level class diagrams

Design → Modeling → Class Diagrams (Basic)

Design → Modelling → Modelling Structure

Class Diagrams - Intermediate

A class diagram can also show different types of associations: inheritance, compositions, aggregations, dependencies.

Modeling inheritance

OOP → Inheritance → What

UML → Class Diagrams → Inheritance → What

Modeling composition

OOP → Associations → Composition

UML → Class Diagrams → Composition → What

Modeling aggregation

OOP → Associations → Aggregation

UML → Class Diagrams → Aggregation → What

Modeling dependencies

OOP → Associations → Dependencies

UML → Class Diagrams → Dependencies → What

A class diagram can also show different types of class-like entities:

Modeling enumerations

OOP → Classes → Enumerations

UML → Class Diagrams → Enumerations → What

Modeling abstract classes

OOP → Inheritance → Abstract Classes

UML → Class Diagrams → Abstract Classes → What

Modeling interfaces

OOP → Inheritance → Interfaces

UML → Class Diagrams → Interfaces → What

Exercises



W6.2 Can use basic-level sequence diagrams
W6.2a Can draw basic sequence diagrams

Design → Modelling → Modelling Behaviors

Sequence Diagrams - Basic

UML Sequence Diagrams → Introduction

UML Sequence Diagrams → Basic Notation

UML Sequence Diagrams → Loops

UML Sequence Diagrams → Object Creation

UML Sequence Diagrams → Minimal Notation

Exercises


Evidence:

Draw a Sequence Diagram for code snippet



W6.3 Can interpret an architecture diagram
W6.3a Can explain what is software design

Design → Introduction →

What

Design in the creative process of transforming the problem into a solution; the solution is also called design. -- 📖 Software Engineering Theory and Practice, Shari Lawrence; Atlee, Joanne M. Pfleeger

Software design has two main aspects:

  • Product/external design: designing the external behavior of the product to meet the users' requirements. This is usually done by product designers with the input from business analysts, user experience experts, user representatives, etc.
  • Implementation/internal design: designing how the product will be implemented to meet the required external behavior. This is usually done by software architects and software engineers.

W6.3b Can interpret an architecture diagram

Design → Architecture → Introduction → What

Design → Architecture → Architecture Diagrams →

Reading

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.3c Can explain multi-level design

Design → Introduction →

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-level3 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-level4 depicts the high-level design of the software.

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

 



   

Evidence:

Covered by the project. In particular, when getting started on modifying AB-4, you are recommended to start by doing local changes (i.e., changes local to a component) first and then move to global changes (i.e., changes that touch multiple components). As AB-4 users multi-level design, you should be able to do most of the local changes without having to learn internal details of the other components.



Implementation

W6.4 Can use logging
W6.4a Can explain logging

Implementation → Error Handling → Logging →

What

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 black box of an airplane; they don't prevent problems but they can be helpful in understanding what went wrong after the fact.

Exercises


W6.4b Can use logging

Implementation → Error Handling → Logging →

How

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 intensity .

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

Resources

Tutorials:

  • A video tutorial by SimplyCoded:

Best Practices:



Evidence:

Use of logging in the code you have written in the module project or elsewhere.



W6.5 Can use assertions
W6.5a Can explain assertions

Implementation → Error Handling → Assertions →

What

Assertions are used to define assumptions about the program state so that the runtime can verify them. An assertion failure indicates a possible bug in the code because the code has resulted in a program state that violates an assumption about how the code should behave.

An assertion can be used to express something like when the execution comes to this point, the variable v cannot be null.

If the runtime detects an assertion failure, it typically take some drastic action such as terminating the execution with an error message. This is because an assertion failure indicates a possible bug and the sooner the execution stops, the safer it is.

In the Java code below, suppose we set an assertion that timeout returned by Config.getTimeout() is greater than 0. Now, if the Config.getTimeout() returned -1 in a specific execution of this line, the runtime can detect it as a assertion failure -- i.e. an assumption about the expected behavior of the code turned out to be wrong which could potentially be the result of a bug -- and take some drastic action such as terminating the execution.

int timeout = Config.getTimeout(); 

W6.5b Can use assertions

Error Handling → Assertions → What

Implementation → Error Handling → Assertions →

How

Use the assert keyword to define assertions.

This assertion will fail with the message x should be 0 if x is not 0 at this point.

x = getX();
assert x == 0 : "x should be 0";
...

Assertions can be disabled without modifying the code.

java -enableassertions HelloWorld (or java -ea HelloWorld) will run HelloWorld with assertions enabled while java -disableassertions HelloWorld will run it without verifying assertions.

Java disables assertions by default. This could create a situation where you think all assertions are being verified as true while in fact they are not being verified at all. Therefore, remember to enable assertions when you run the program if you want them to be in effect.

💡 Enable assertions in Intellij (how?) and get an assertion to fail temporarily (e.g. insert an assert false into the code temporarily) to confirm assertions are being verified.

Java assert vs JUnit assertions: They are similar in purpose but JUnit assertions are more powerful and customized for testing. In addition, JUnit assertions are not disabled by default. We recommend you use JUnit assertions in test code and Java assert in functional code.

Resources

Tutorials:

Best practices:



Evidence:

Explain assertions in AddressBook-Level4 code.


W6.5c Can use assertions optimally

Error Handling → Assertions → What

Error Handling → Exceptions → What

Implementation → Error Handling → Assertions →

When

It is recommended that assertions be used liberally in the code. Their impact on performance is considered low and worth the additional safety they provide.

Do not use assertions to do work because assertions can be disabled. If not, your program will stop working when assertions are not enabled.

The code below will not invoke the writeFile() method when assertions are disabled.  If that method is performing some work that is necessary for your program, your program will not work correctly when assertions are disabled.

...
assert writeFile() : "File writing is supposed to return true";

Assertions are suitable for verifying assumptions about Internal Invariants, Control-Flow Invariants, Preconditions, Postconditions, and Class Invariants. Refer to [Programming with Assertions (second half)] to learn more.

Exceptions and assertions are two complementary ways of handling errors in software but they serve different purposes. Therefore, both assertions and exceptions should be used in code.

  • The raising of an exception indicates an unusual condition created by the user  (e.g. user inputs an unacceptable input) or the environment  (e.g., a file needed for the program is missing).
  • An assertion failure indicates the programmer made a mistake in the code  (e.g., a null value is returned from a method that is not supposed to return null under any circumstances).

Exercises


Evidence:

Give an example from the AddressBook-Level4 code where an exception is used and explain why an assertion is not suitable for that situation. Similarly, explain why an exception is not suitable for a place where AddressBook Level4 uses an assertion.



W6.6 Can use Java8 streams
W6.6a Can use Java8 streams :

Tools → Java →

Streams: Basic

Java 8 introduced a number of new features (e.g. Lambdas, Streams) that are not trivial to learn but also extremely useful to know.

Here is an overview of new Java 8 features . (written by Benjamin Winterberg)

Resources

Tutorials:

 



 


Evidence:

Some code you have written (can be toy examples) that uses some Java 8 features.



W6.7 Can use JavaFX to build a simple GUI
W6.7a Can use JavaFX to build a simple GUI

Tools → Java →

JavaFX: Basic

Adapted (with permissions) from Marco Jakob's JavaFX 8 tutorial.

After going through the two parts above, you should be familiar with building basic JavaFX GUIs using IntelliJ. You can continue with the original tutorial (which is written for Eclipse), with the following links:

Evidence:

Using JavaFX in any past project. Suggested: Do the exercise in [Addressbook-Level3: LO-JavaFX]



Project Management

W6.8 Can explain continuous integration and continuous deployment
W6.8a Can explain integration

Implementation → Integration → Introduction →

What

Combining parts of a software product to form a whole is called integration. It is also one of the most troublesome tasks and it rarely goes smoothly.


W6.8b Can explain build automation tools

Implementation → Integration → Build Automation →

What

Build automation tools automate the steps of the build process, usually by means of build scripts.

In a non-trivial project, building a product from source code can be a complex multi-step process.  For example, it can include steps such as to pull code from the revision control system, compile, link, run automated tests, automatically update release documents (e.g. build number), package into a distributable, push to repo, deploy to a server, delete temporary files created during building/testing, email developers of the new build, and so on. Furthermore, this build process can be done ‘on demand’, it can be scheduled (e.g. every day at midnight) or it can be triggered by various events (e.g. triggered by a code push to the revision control system).

Some of these build steps such as to compile, link and package are already automated in most modern IDEs.  For example, several steps happen automatically when the ‘build’ button of the IDE is clicked. Some IDEs even allow customization to this build process to some extent.

However, most big projects use specialized build tools to automate complex build processes.

Some popular build tools relevant to Java developers:

Some other build tools : Grunt (JavaScript), Rake (Ruby)

Some build tools also serve as dependency management tools. Modern software projects often depend on third party libraries that evolve constantly. That means developers need to download the correct version of the required libraries and update them regularly. Therefore, dependency management is an important part of build automation. Dependency Management tools can automate that aspect of a project.

Maven and Gradle, in addition to managing the build process, can play the role of dependency management tools too.

Resources

Working With Gradle in Intellij IDEA (6 minutes)


Exercises


Evidence:

  1. Explain what Gradle is and how it helps in the AddressBook project.
  2. Run various project tasks using Gradle as described in [AddressBook - Level 4: Using Gradle] e.g. run tests in headless mode

W6.8c Can explain continuous integration and continuous deployment

Implementation → Integration → Build Automation →

Continuous Integration and Continuous Deployment

An extreme application of build automation is called continuous integration (CI) in which integration, building, and testing happens automatically after each code change.

A natural extension of CI is Continuous Deployment (CD) where the changes are not only integrated continuously, but also deployed to end-users at the same time.

Some examples of CI/CD tools:

Resources



Evidence:

  1. Explain what Travis is and how it helps in the AddressBook project.
  2. One member: Set up Travis for your team repo by following [AddressBook - Level 4: Using Travis]


🅿️ Project

W6.9 Can work with a 3KLoC code base

[Optional, but recommended] If you are not comfortable jumping from AB-2 (~2KLoc) straight to AB-4 (~10KLoc), we recommend that you play around with [AddressBook - Level3] for a bit before moving to AB-4. As before, fork, clone, set up project in your Computer, and try to do a small enhancement to AB-3.

How AB-3 differs from AB-2:

  • A simple GUI has been added to replace the Text UI.
  • No more I/O tests
  • A Logic class has been added together with a LogicTest class.

W6.10 Can contribute to project documentation

Covered by:

Admin Project → mid-v1.1


Tutorial 6

Questions to do during tutorial:

Explain notations in the class diagram

Explain Sequence Diagram about Machine

Draw a Class Diagram for Item etc.

Draw a Sequence Diagram for code snippet


Evidence for weekly LOs (for reference)

Lecture 6

Questions to discuss during the lecture:

Find notation errors in sequence diagram