[TE3201]
  • Schedule
  • Admin
  • SE Book - Full
  • SE Book - Printer Friendly
  • Programming Basics
  • IVLE
  • Instructor
  • Learning Outcomes

    Design

    Abstraction

    Design β†’ Design Fundamentals β†’ Abstraction β†’

    What

    Abstraction is a technique for dealing with complexity. It works by establishing a level of complexity (or an aspect) we are interested in, and suppressing the more complex details below that level (or irrelevant to that aspect).

    Most programs are written to solve complex problems involving large amounts of intricate details. It is impossible to deal with all these details at the same time. The guiding principle of abstraction stipulates that we capture only details that are relevant to the current perspective or the task at hand.

    Ignoring lower level data items and thinking in terms of bigger entities is called data abstraction.

    πŸ“¦ Within a certain software component, we might deal with a user data type, while ignoring the details contained in the user data item such as name, and date of birth. These details have been β€˜abstracted away’ as they do not affect the task of that software component.

    Control abstraction abstracts away details of the actual control flow to focus on tasks at a simplified level.

    πŸ“¦ print(β€œHello”) is an abstraction of the actual output mechanism within the computer.

    Abstraction can be applied repeatedly to obtain progressively higher levels of abstractions.

    πŸ“¦ An example of different levels of data abstraction: a File is a data item that is at a higher level than an array and an array is at a higher level than a bit.

    πŸ“¦ An example of different levels of control abstraction: execute(Game) is at a higher level than print(Char) which is at a higher than an Assembly language instruction MOV.

    Modeling

    Design β†’ Modelling β†’ Introduction β†’

    What

    A model is a representation of something else.

    πŸ“¦ A class diagram is a model that represents a software design.

    A class diagram is a diagram drawn using the UML modelling notation.
    πŸ“¦ An example class diagram:

    A model provides a simpler view of a complex entity because a model captures only a selected aspect. This omission of some aspects implies models are abstractions.

    Design β†’ Design Fundamentals β†’ Abstraction β†’

    What

    Abstraction is a technique for dealing with complexity. It works by establishing a level of complexity (or an aspect) we are interested in, and suppressing the more complex details below that level (or irrelevant to that aspect).

    Most programs are written to solve complex problems involving large amounts of intricate details. It is impossible to deal with all these details at the same time. The guiding principle of abstraction stipulates that we capture only details that are relevant to the current perspective or the task at hand.

    Ignoring lower level data items and thinking in terms of bigger entities is called data abstraction.

    πŸ“¦ Within a certain software component, we might deal with a user data type, while ignoring the details contained in the user data item such as name, and date of birth. These details have been β€˜abstracted away’ as they do not affect the task of that software component.

    Control abstraction abstracts away details of the actual control flow to focus on tasks at a simplified level.

    πŸ“¦ print(β€œHello”) is an abstraction of the actual output mechanism within the computer.

    Abstraction can be applied repeatedly to obtain progressively higher levels of abstractions.

    πŸ“¦ An example of different levels of data abstraction: a File is a data item that is at a higher level than an array and an array is at a higher level than a bit.

    πŸ“¦ An example of different levels of control abstraction: execute(Game) is at a higher level than print(Char) which is at a higher than an Assembly language instruction MOV.

    πŸ“¦ A class diagram captures the structure of the software design but not the behavior.

    Multiple models of the same entity may be needed to capture it fully.

    πŸ“¦ In addition to a class diagram (or even multiple class diagrams), a number of other diagrams may be needed to capture various interesting aspects of the software.

    Design β†’ Modelling β†’ Introduction β†’

    How

    In software development, models are useful in several ways:

    a) To analyze a complex entity related to software development.

    πŸ“¦ Some examples of using models for analysis:

    1. Models of the problem domain (i.e. the environment in which the software is expected to solve a problem) can be built to aid the understanding of the problem to be solved.
    2. When planning a software solution, models can be created to figure out how the solution is to be built. An architecture diagram is such a model.

    b) To communicate information among stakeholders. Models can be used as a visual aid in discussions and documentations.

    πŸ“¦ Some examples of using models to communicate:

    1. We can use an architecture diagram to explain the high-level design of the software to developers.
    2. A business analyst can use a use case diagram to explain to the customer the functionality of the system.
    3. A class diagram can be reverse-engineered from code so as to help explain the design of a component to a new developer.

    An architecture diagram depicts the high-level design of a software.

    c) As a blueprint for creating software. Models can be used as instructions for building software.

    πŸ“¦ Some examples of using models to as blueprints:

    1. A senior developer draws a class diagram to propose a design for an OOP software and passes it to a junior programmer to implement.
    2. A software tool allows users to draw UML models using its interface and the tool automatically generates the code based on the model.

    Model-driven development (MDD), also called Model-driven engineering, is an approach to software development that strives to exploits models as blueprints. MDD uses models as primary engineering artifacts when developing software. That is, the system is first created in the form of models. After that, the models are converted to code using code-generation techniques (usually, automated or semi-automated, but can even involve manual translation from model to code). MDD requires the use of a very expressive modeling notation (graphical or otherwise), often specific to a given problem domain. It also requires sophisticated tools to generate code from models and maintain the link between models and the code. One advantage of MDD is that the same model can be used to create software for different platforms and different languages. MDD has a lot of promise, but it is still an emerging technology

    Further reading:

    Choose the correct statements about models.

    • a. Models are abstractions.
    • b. Models can be used for communication.
    • c. Models can be used for analysis of a problem.
    • d. Generating models from code is useless.
    • e. Models can be used as blueprints for generating code.

    (a) (b) (c) (e)

    Explanation: Models generated from code can be used for understanding, analysing, and communicating about the code.

    Explain how models (e.g. UML diagrams) can be used in a class project.

    Can models be useful in evaluating the design quality of a software written by students?

    Design β†’ Modelling β†’ Introduction β†’

    UML Models

    The following diagram uses the class diagram notation to show the different types of UML diagrams.


    source:https://en.wikipedia.org/

    Modeling Structures

    Design β†’ Modelling β†’ Modelling Structure

    Class Diagrams (Basics)

    Classes form the basis of class diagrams. Associations among objects/classes play an important role in an OO solution.

    The most basic class diagram is a bunch of classes with some solid lines among them to represent associations, such as this one.

    πŸ“¦ An example class diagram showing associations between classes.

    In addition, associations can show additional decorations such as association labels, association roles, multiplicity and navigability to add more information to a class diagram.

    πŸ“¦ Here is the same class diagram shown earlier but with some additional information included:

    Which association notatations are shown in this diagram?

    • a. association labels
    • b. association roles
    • c. association multiplicity
    • d. class names

    (a) (b) (c) (d)

    Explanation: '1’ is a multiplicity, β€˜mentored by’ is a label, and β€˜mentor’ is a role.

    Explain the associations, navigabilities, and multiplicities in the class diagram below:

    Design β†’ Modeling β†’

    Class Diagrams - Intermediate

    Compositions and Aggregations are stronger forms of associations while Dependencies are a weaker form of associations. Inheritance is another strong type of association between classes.

    Design β†’ Modeling β†’

    Object Diagrams

    An object diagrams shows the object structure (i.e., objects and their associations) at a specific time.

    An object diagram shows an object structure at a given point of time.

    Modeling Behaviors

    Design β†’ Modeling β†’

    Use Case Diagrams

    Use case diagrams model the mapping between features of a system and its user roles.

    πŸ“¦ A simple use case diagram:

    Design β†’ Modeling β†’

    Activity Diagrams

    Software projects often involve workflows. Workflows define the flow in which a process or a set of tasks is executed.

    Some examples in which a certain workflow is relevant to software project:

    πŸ“¦ A software that automates the work of an insurance company needs to take into account the workflow of processing an insurance claim.

    πŸ“¦ The algorithm of a price of code represents the workflow (i.e. the execution flow) of the code.

    Understanding such workflows is important for the success of the software project. UML Β activity diagrams (AD) can model workflows.Β  Flow charts is another type of diagrams that can model workflows. Activity diagrams are the UML equivalent of flow charts.

    Unified Modeling Language (UML) is a graphical notation to describe various aspects of a software system. UML is the brainchild of three software modeling specialists James Rumbaugh, Grady Booch and Ivar Jacobson (also known as the Three Amigos). Each of them has developed their own notation for modeling software systems before joining force to create a unified modeling language (hence, the term β€˜Unified’ in UML). UML is currently the de facto modeling notation used in the software industry.

    πŸ“¦ An example activity diagram [source:wikipeida]:

    The most basic activity diagram is simply a linear sequence of actions.

    Some workflows have alternate paths where only one of the alternate paths is taken based on some condition.

    In some workflows, multiple paths happen in parallel.

    Which of these sequence of actions is not allowed by the given activity diagram?

    • i. start a b c d end
    • ii. start a b c d e f g c d end
    • iii. start a b c d e g f c d end
    • iv. start a b c d g c d end

    (iv)

    Explanation: -e-f- and -g- are parallel paths. Both paths should complete before the execution reaches c again.

    Implementation

    Reuse

    Implementation β†’ Reuse β†’ Introduction β†’

    What

    Reuse is a major theme in software engineering practices. By reusing tried-and-tested components, the robustness of a new software system can be enhanced while reducing the manpower and time requirement. Reusable components come in many forms; it can be reusing a piece of code, a subsystem, or a whole software.

    Implementation β†’ Reuse β†’ Introduction β†’

    When

    While you may be tempted to use many libraries/frameworks/platform that seem to crop up on a regular basis and promise to bring great benefits, note that there are costs associated with reuse. Here are some:

    • The reused code may be an overkill (think using a sledgehammer to crack a nut) increasing the size of, or/and degrading the performance of, your software.
    • The reused software may not be mature/stable enough to be used in an important product. That means the software can change drastically and rapidly, possibly in ways that break your software.
    • Non-mature software has the risk of dying off as fast as they emerged, leaving you with a dependency that is no longer maintained.
    • The license of the reused software (or its dependencies) restrict how you can use/develop your software.
    • The reused software might have bugs, missing features, or security vulnerabilities that are important to your product but not so important to the maintainers of that software, which means those flaws will not get fixed as fast as you need them to.
    • Malicious code can sneak into your product via compromised dependencies.

    One of your teammates is proposing to use a recently-released β€œcool” UI framework for your class project. List the pros and cons of this idea.

    Pros

    • The potential to create a much better product by reusing the framework.
    • Learning a new framework is good for the future job prospects.

    Cons

    • Learning curve may be steep.
    • May not be stable (it was recently released).
    • May not allow us to do exactly what we want. While frameworks allow customization, such customization can be limited.
    • Performance penalties.
    • Might interfere with learning objectives of the module.

    Note that having more cons does not mean we should not use this framework. Further investigation is required before we can make a final decision.

    APIs

    Implementation β†’ Reuse β†’ APIs β†’

    What

    An Application Programming Interface (API) specifies the interface through which other programs can interact with a software component. It is a contract between the component and its clients.

    πŸ“¦ A class has an API (e.g., API of the Java String class, API of the Python str class) which is a collection of public methods that you can invoke to make use of the class.

    πŸ“¦ The GitHub API is a collection of Web request formats GitHub server accepts and the corresponding responses. We can write a program that interacts with GitHub through that API.

    When developing large systems, if you define the API of each components early, the development team can develop the components in parallel Β because the future behavior of the other components are now more predictable.

    Choose the correct statements

    • a. A software component can have an API.
    • b. Any method of a class is part of its API.
    • c. Private methods of a class are not part of its API.
    • d. The API forms the contract between the component developer and the component user.
    • e. Sequence diagrams can be used to show how components interact with each other via APIs.

    (a) (c) (d) (e)

    Explanation: (b) is incorrect because private methods cannot be a part of the API

    Defining component APIs early is useful for developing components in parallel.

    True

    Explanation: Yes, once we know the precise behavior expected of each component, we can start developing them in parallel.

    Libraries

    Implementation β†’ Reuse β†’ Libraries β†’

    What

    A library is a collection of modular code that is general and can be used by other programs.

    πŸ“¦ Java classes you get with the JDK (such as String, ArrayList, HashMap, etc.) are library classes that are provided in the default Java distribution.

    πŸ“¦ Natty is a Java library that can be used for parsing strings that represent dates e.g. The 31st of April in the year 2008

    πŸ“¦ built-in modules you get with Python (such as csv, random, sys, etc.) are libraries that are provided in the default Python distribution. Classes such as list, str, dict are built-in library classes that you get with Python.

    πŸ“¦ Colorama is a Python library that can be used for colorizing text in a CLI.


    Implementation β†’ Reuse β†’ Libraries β†’

    How

    These are the typical steps required to use a library.

    1. Read the documentation to confirm that its functionality fits your needs
    2. Check the license to confirm that it allows reuse in the way you plan to reuse it. For example, some libraries might allow non-commercial use only.
    3. Download the library and make it accessible to your project. Alternatively, you can configure your dependency management tool to do it for you.
    4. Call the library API from your code where you need to use the library functionality.

    Frameworks

    Implementation β†’ Reuse β†’ Frameworks β†’

    What

    The overall structure and execution flow of a specific category of software systems can be very similar. The similarity is an opportunity to reuse at a high scale.

    πŸ“¦ Running example:

    IDEs for different programming languages are similar in how they support editing code, organizing project files, debugging, etc.

    A software framework is a reusable implementation of a software (or part thereof) providing generic functionality that can be selectively customized to produce a specific application.

    πŸ“¦ Running example:

    Eclipse is an IDE framework that can be used to create IDEs for different programming languages.

    Some frameworks provide a complete implementation of a default behavior which makes them immediately usable.

    πŸ“¦ Running example:

    Eclipse is a fully functional Java IDE out-of-the-box.

    A framework facilitates the adaptation and customization of some desired functionality.

    πŸ“¦ Running example:

    Eclipse plugin system can be used to create an IDE for different programming languages while reusing most of the existing IDE features of Eclipse. E.g. https://marketplace.eclipse.org/content/pydev-python-ide-eclipse

    Some frameworks cover only a specific components or an aspect.

    πŸ“¦ JavaFx a framework for creating Java GUIs. TkInter is a GUI framework for Python.

    πŸ“¦ More examples of frameworks

    • Frameworks for Web-based applications: Drupal(PHP), Django(Python), Ruby on Rails (Ruby), Spring (Java)
    • Frameworks for testing: JUnit (Java), unittest (Python), Jest (Java Script)

    Implementation β†’ Reuse β†’ Frameworks β†’

    Frameworks vs Libraries

    Although both frameworks and libraries are reuse mechanisms, there are notable differences:

    • Libraries are meant to be used β€˜as is’ while frameworks are meant to be customized/extended. Β e.g., writing plugins for Eclipse so that it can be used as an IDE for different languages (C++, PHP, etc.), adding modules and themes to Drupal, and adding test cases to JUnit.

    • Your code calls the library code while the framework code calls your code. Frameworks use a technique called inversion of control, aka the β€œHollywood principle” (i.e. don’t call us, we’ll call you!). That is, you write code that will be called by the framework, Β e.g. writing test methods that will be called by the JUnit framework. In the case of libraries, your code calls libraries.

    Choose correct statements about software frameworks.

    • a. They follow the hollywood principle, otherwise known as β€˜inversion of control’
    • b. They come with full or partial implementation.
    • c. They are more concrete than patterns or principles.
    • d. They are often configurable.
    • e. They are reuse mechanisms.
    • f. They are similar to reusable libraries but bigger.

    (a)(b)(c)(d)(e)(f)

    Explanation: While both libraries and frameworks are reuse mechanisms, and both more concrete than principles and patterns, libraries differ from frameworks in some key ways. One of them is the β€˜inversion of control’ used by frameworks but not libraries. Furthermore, frameworks do not have to be bigger than libraries all the time.

    Which one of these are frameworks ?

    (a)(b)(c)(d)

    Explanation: These are frameworks.

    Platforms

    Implementation β†’ Reuse β†’ Platforms β†’

    What

    A platform provides a runtime environment for applications. A platform is often bundled with various libraries, tools, frameworks, and technologies in addition to a runtime environment but the defining characteristic of a software platform is the presence of a runtime environment.

    πŸ“¦ Technically, an operating system can be called a platform. For example, Windows PC is a platform for desktop applications while iOS is a platform for mobile apps.

    πŸ“¦ Two well-known examples of platforms are JavaEE and .NET, both of which sit above Operating systems layer, and are used to develop enterprise applications. Infrastructure services such as connection pooling, load balancing, remote code execution, transaction management, authentication, security, messaging etc. are done similarly in most enterprise applications. Both JavaEE and .NET provide these services to applications in a customizable way without developers having to implement them from scratch every time.

    • JavaEE (Java Enterprise Edition) is both a framework and a platform for writing enterprise applications. The runtime used by the JavaEE applications is the JVM (Java Virtual Machine) that can run on different Operating Systems.
    • .NET is a similar platform and a framework. Its runtime is called CLR (Common Language Runtime) and usually used on Windows machines.

    Enterprise Application: β€˜enterprise applications’ means software applications used at organizations level and therefore has to meet much higher demands (such as in scalability, security, performance, and robustness) than software meant for individual use.

    Cloud Computing

    Implementation β†’ Reuse β†’ Cloud Computing β†’

    What

    Cloud computing is the delivery of computing as a service over the network, rather than a product running on a local machine. This means the actual hardware and software is located at a remote location, typically, at a large server farm, while users access them over the network. Maintenance of the hardware and software is managed by the cloud provider while users typically pay for only the amount of services they use. This model is similar to the consumption of electricity; the power company manages the power plant, while the consumers pay them only for the electricity used. The cloud computing model optimizes hardware and software utilization and reduces the cost to consumers. Furthermore, users can scale up/down their utilization at will without having to upgrade their hardware and software. The traditional non-cloud model of computing is similar to everyone buying their own generators to create electricity for their own use.

    Implementation β†’ Reuse β†’ Cloud Computing β†’

    Iaas, PaaS, and SaaS


    source:https://commons.wikimedia.org

    Cloud computing can deliver computing services at three levels:

    1. Infrastructure as a service (IaaS) delivers computer infrastructure as a service. For example, a user can deploy virtual servers on the cloud instead of buying physical hardware and installing server software on them. Another example would be a customer using storage space on the cloud for off-site storage of data. Β Rackspace is an example of an IaaS cloud provider. Amazon Elastic Compute Cloud (Amazon EC2) is another one.

    2. Platform as a service (PaaS) provides a platform on which developers can build applications. Developers do not have to worry about infrastructure issues such as deploying servers or load balancing as is required when using IaaS. Those aspects are automatically taken care of by the platform. The price to pay is reduced flexibility; applications written on PaaS are limited to facilities provided by the platform. Β A PaaS example is the Google App Engine where developers can build applications using Java, Python, PHP, or Go whereas Amazon EC2 allows users to deploy application written in any language on their virtual servers.

    3. Software as a service (SaaS) allows applications to be accessed over the network instead of installing them on a local machine. Β For example, Google Docs is an SaaS word processing software, while Microsoft Word is a traditional word processing software.

    Google Calendar belongs to which category of cloud computing services?

    • a. IaaS
    • b. PaaS
    • c. SaaS

    (c)

    Explanation: It is a software as a service. Instead of installing a calendar software on your desktop, we can use the Google Calendar software that lives β€˜on the cloud’.

    Documentation

    Implementation β†’ Documentation β†’ Introduction β†’

    What

    Developer-to-developer documentation can be in one of two forms:

    1. Documentation for developer-as-user: Software components are written by developers and reused by other developers, which means there is a need to document how such components are to be used. Such documentation can take several forms:
      • API documentation: APIs expose functionality in small-sized, independent and easy-to-use chunks, each of which can be documented systematically.
      • Tutorial-style instructional documentation: In addition to explaining functions/methods independently, some higher-level explanations of how to use an API can be useful.

    1. Documentation for developer-as-maintainer: There is a need to document how a system or a component is designed, implemented and tested so that other developers can maintain and evolve the code. Writing documentation of this type is harder because of the need to explain complex internal details. However, given that readers of this type of documentation usually have access to the source code itself, only some information need to be included in the documentation, as code (and code comments) can also serve as a complementary source of information.

    Choose correct statements about API documentation.

    • a. They are useful for both developers who use the API and developers who maintain the API implementation.
    • b. There are tools that can generate API documents from code comments.
    • d. API documentation may contain code examples.

    All

    Given below are some guidelines to write developer documentation.

    Implementation β†’ Documentation β†’ Guidelines β†’ Aim for Comprehensibility β†’

    What

    Technical documents exist to help others understand technical details. Therefore, it is not enough for the documentation to be accurate and comprehensive, it should also be comprehensible too.

    Implementation β†’ Documentation β†’ Guidelines β†’ Aim for Comprehensibility β†’

    How

    Here are some tips on writing effective documentation.

    • Use plenty of diagrams: It is not enough to explain something in words; complement it with visual illustrations (e.g. a UML diagram).
    • Use plenty of examples: When explaining algorithms, show a running example to illustrate each step of the algorithm, in parallel to worded explanations.
    • Use simple and direct explanations: Convoluted explanations and fancy words will annoy readers. Avoid long sentences.
    • Get rid of statements that do not add value: For example, 'We made sure our system works perfectly' (who didn't?), 'Component X has its own responsibilities' (of course it has!).
    • It is not a good idea to have separate sections for each type of artifact, such as 'use cases', 'sequence diagrams', 'activity diagrams', etc. Such a structure, coupled with the indiscriminate inclusion of diagrams without justifying their need, indicates a failure to understand the purpose of documentation. Include diagrams when they are needed to explain something. If you want to provide additional diagrams for completeness' sake, include them in the appendix as a reference.

    It is recommended for developer documents,

    • a. to have separate sections for each type of diagrams such as class diagrams, sequence diagrams, use case diagrams etc.
    • b. to give a high priority to comprehension too, not stop at comprehensiveness only.

    (a)(b)

    Explanation:

    (a) Use diagrams when they help to understand the text descriptions. Text and diagrams should be used in tandem. Having separate sections for each diagram type is a sign of generating diagrams for the sake of having them.

    (b) Both are important, but lengthy, complete, accurate yet hard to understand documents are not that useful.

    Implementation β†’ Documentation β†’ Guidelines β†’ Minimal but Sufficient β†’

    What

    Aim for 'just enough' developer documentation.

    • Writing and maintaining developer documents is an overhead. You should try to minimize that overhead.
    • If the readers are developers who will eventually read the code, the documentation should complement the code and should provide only just enough guidance to get started.

    Implementation β†’ Documentation β†’ Guidelines β†’ Minimal but Sufficient β†’

    How

    Anything that is already clear in the code need not be described in words. Instead, focus on providing higher level information that is not readily visible in the code or comments.

    Refrain from duplicating chunks or text. When describing several similar algorithms/designs/APIs, etc., do not simply duplicate large chunks of text. Instead, describe the similarity in one place and emphasize only the differences in other places. It is very annoying to see pages and pages of similar text without any indication as to how they differ from each other.

    Project Management

    Revision Control

    Project Management β†’ Revision Control β†’

    What

    Revision Control Software (RCS) are the software tools that automate the process of Revision Control i.e. managing revisions of software artifacts.

    Revision control is also known as Version Control Software (VCS), and a few other names. Here, we use the terms revision and version interchangeably.

    Revision control is the process of managing multiple versions of a piece of information. In its simplest form, this is something that many people do by hand: every time you modify a file, save it under a new name that contains a number, each one higher than the number of the preceding version.

    Manually managing multiple versions of even a single file is an error-prone task, though, so software tools to help automate this process have long been available. The earliest automated revision control tools were intended to help a single user to manage revisions of a single file. Over the past few decades, the scope of revision control tools has expanded greatly; they now manage multiple files, and help multiple people to work together. The best modern revision control tools have no problem coping with thousands of people working together on projects that consist of hundreds of thousands of files.

    There are a number of reasons why you or your team might want to use an automated revision control tool for a project. It will track the history and evolution of your project, so you don't have to. For every change, you'll have a log of who made it; why they made it; when they made it; and what the change was.

    When you're working with other people, revision control software makes it easier for you to collaborate. For example, when people more or less simultaneously make potentially incompatible changes, the software will help you to identify and resolve those conflicts.

    It can help you to recover from mistakes. If you make a change that later turns out to be an error, you can revert to an earlier version of one or more files. In fact, a really good revision control tool will even help you to efficiently figure out exactly when a problem was introduced.

    It will help you to work simultaneously on, and manage the drift between, multiple versions of your project. Most of these reasons are equally valid, at least in theory, whether you're working on a project by yourself, or with a hundred other people.

    -- [adapted from bryan-mercurial-guide]



    Mercurial: The Definitive Guide by Bryan O'Sullivan retrieved on 2012/07/11

    Revision Control Software

    In the context of RCS, what is a Revision? Give an example.

    Versions of a piece of information. For example, take a file containing program code. If you modify the code and save the file, you have a new version of that file.

    • a. Help a single user manage revisions of a single file
    • b. Help a developer recover from a incorrect modification to a code file
    • c. Makes it easier for a group of developers to collaborate on a project
    • d. Manage the drift between multiple versions of your project
    • e. Detect when multiple developers make incompatible changes to the same file
    • f. All of them are benefits of RCS

    f

    Suppose You are doing a team project with Tom, Dick, and Harry but those three have not even heard the term RCS. How do you explain RCS to them as briefly as possible, using the project as an example?

    Tools

    UML notations given in the panel below are just for reference; they were covered in other sections already.

    Class Diagrams

    Introduction

    Tools β†’ UML β†’ Class Diagrams β†’ Introduction β†’

    What

    UML class diagrams describe the structure (but not the behavior) of an OOP solution. These are possibly the most often used diagrams in the industry and an indispensable tool for an OO programmer.

    πŸ“¦ An example class diagram:


    Classes

    Tools β†’ UML β†’ Class Diagrams β†’ Classes β†’

    What

    The basic UML notations used to represent a class:

    πŸ“¦ A Table class shown in UML notation:

    Java ‡️

    class Table{
        
        Integer number;
        Chair[] chairs = null;
        
        Integer getNumber(){
            //...
        }
        
        void setNumber(Integer n){
            //...
        }
    }
    

    Β Β 

    Python ‡️

    class Table:
        
      def __init__(self):
        self.number = 0
        self.chairs = []
        
      def get_number(self):
        # ...
      
        
      def set_number(self, n):
        # ...
        
    

    The 'Operations' compartment and/or the 'Attributes' compartment may be omitted if such details are not important for the task at hand. 'Attributes' always appear above the 'Operations' compartment. All operations should be in one compartment rather than each operation in a separate compartment. Same goes for attributes.

    The visibility of attributes and operations is used to indicate the level of access allowed for each attribute or operation. The types of visibility and their exact meanings depend on the programming language used. Here are some common visibilities and how they are indicated in a class diagram:

    • + : public
    • - : private
    • # : protected
    • ~ : package private
    visibility Java Python
    - private private at least two leading underscores (and at most one trailing underscores) in the name
    # protected protected one leading underscore in the name
    + public public all other cases
    ~ package private default visibility not applicable

    πŸ“¦ Table class with visibilities shown:

    Which of these follow the correct UML notation?

    • 1
    • 2
    • 3
    • 4
    • 5
    1. Incorrect : Attributes compartment should be above the Methods compartment.
    2. Incorrect : All attributes should be inside the same compartment.
    3. Correct
    4. Correct : Both Attributes and Methods compartments can be omitted.
    5. Correct : The Attributes and Methods compartments can be empty.

    Draw a UML diagram to represent the Car class as given below. Include visibilities.

    class Car{
        
        Engine engine;
        private List<Wheel>[] wheels = null;
        public String model;
        
        public void drive(int speed){
            move(speed);
        }
        
        private move(int speed){
            ...
        }
    }
    

    πŸ’‘ You may omit self from method signatures in the class diagram.

    class Car:
        
      def __init__(self, model):
        self._engine = None # type: Engine
        self.__wheels = []  # type: a list of Wheel objects
        self.model = model  # type: string
        
        def drive(self, speed): # speed is an int
          self.move(speed)
        
        def __move(self, speed):
          pass
    


    Associations

    Tools β†’ UML β†’ Class Diagrams β†’ Associations β†’

    Basic

    We use a solid line to show an association between two classes.

    πŸ“¦ This example shows an association between the Admin class and the Student class:


    Tools β†’ UML β†’ Class Diagrams β†’ Associations β†’

    We use arrow heads to indication the navigability of an association.

    πŸ“¦ Logic is aware of Minefield, but Minefield is not aware of Logic

    Java ‡️

    class Logic{
        Minefield minefield;
    }
    
    class Minefield{
        ...
    }
    
    
    
    

    Β Β 

    Python ‡️

    class Logic:
      
      def __init__(self, minefield):
        self.minefield = minefield
        
      # ...
    
    
    class Minefield:
      # ...
    

    πŸ“¦ Here is an example of a bidirectional navigability; each class is aware of the other.

    Navigability can be shown in class diagrams as well as object diagrams.

    πŸ“¦ According to this object diagram the given Logic object is associated with and aware of two MineField objects.


    Tools β†’ UML β†’ Class Diagrams β†’ Associations β†’

    Roles

    Association Role labels are used to indicate the role played by the classes in the association.

    πŸ“¦ This association represents a marriage between a Man object and a Woman object. The respective roles played by objects of these two classes are husband and wife.

    Note how the variable names match closely with the association roles.

    Java ‡️

    class Man{
        Woman wife;
    }
    
    class Woman{
        Man husband;
    }
    

    Β Β 

    Python ‡️

    class Man:
      def __init__(self):
        self.wife = None # a Woman object
    
    class Woman:
       def __init__(self):
         self.husband = None # a Man object
    

    πŸ“¦ The role of Student objects in this association is charges (i.e. Admin is in charge of students)

    Java ‡️

    class Admin{
        List<Student> charges;
    }
    

    Β Β 

    Python ‡️

    class Admin:
      def __init__(self):
        self.charges = [] # list of Student objects
    


    Tools β†’ UML β†’ Class Diagrams β†’ Associations β†’

    Labels

    Association labels describe the meaning of the association. The arrow head indicates the direction in which the label is to be read.

    πŸ“¦ In this example, the same association is described using two different labels.

    • Diagram on the left: Admin class is associated with Student class because an Admin object uses a Student object.
    • Diagram on the right: Admin class is associated with Student class because a Student object is used by an Admin object.

    Tools β†’ UML β†’ Class Diagrams β†’ Associations β†’

    Multiplicity

    Commonly used multiplicities:

    • 0..1 : optional, can be linked to 0 or 1 objects
    • 1 : compulsory, must be linked to one object at all times.
    • * : can be linked to 0 or more objects.
    • n..m : the number of linked objects must be n to m inclusive

    πŸ“¦ In the diagram below, an Admin object administers (in charge of) any number of students but a Student object must always be under the charge of exactly one Admin object

    πŸ“¦ In the diagram below,

    • Each student must be supervised by exactly one professor. i.e. There cannot be a student who doesn't have a supervisor or has multiple supervisors.
    • A professor cannot supervise more than 5 students but can have no students to supervise.
    • An admin can handle any number of professors and any number of students, including none.
    • A professor/student can be handled by any number of admins, including none.

    Associations as Attributes

    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:


    Class Level Members

    Tools β†’ UML β†’ Class Diagrams β†’

    Class-Level Members

    In UML class diagrams, underlines denote class-level attributes and variables.

    πŸ“¦ In the class below, totalStudents attribute and the getTotalStudents method are class-level.


    Composition

    Tools β†’ UML β†’ Class Diagrams β†’

    Composition

    UML uses a solid diamond symbol to denote composition.

    Notation:

    πŸ“¦ A Book consists of Chapter objects. When the Book object is destroyed, its Chapter objects are destroyed too.


    Aggregation

    Tools β†’ UML β†’ Class Diagrams β†’

    Aggregation

    UML uses a hollow diamond is used to indicate an aggregation.

    Notation:

    πŸ“¦ Example:


    Class Inheritance

    Tools β†’ UML β†’ Class Diagrams β†’

    Inheritance

    You can use a triangle and a solid line (not to be confused with an arrow) to indicate class inheritance.

    Notation:

    πŸ“¦ Examples: The Car class inherits from the Vehicle class. The Cat and Dog classes inherit from the Pet class.


    Object Diagrams

    Tools β†’ UML β†’ Object Diagrams β†’

    Introduction

    An object diagram shows an object structure at a given point of time.


    Tools β†’ UML β†’ Object Diagrams β†’

    Objects

    Notation:

    Notes:

    • The class name and object name e.g. car1:Car are underlined.
    • objectName:ClassName is meant to say 'an instance of ClassName identified as objectName'.
    • Unlike classes, there is no compartment for methods.
    • Attributes compartment can be omitted if it is not relevant to the task at hand.
    • Object name can be omitted too e.g. :Car which is meant to say 'an unnamed instance of a Car object'.

    πŸ“¦ Some example objects:

    Draw a UML diagram to represent the Car object created by the following code.

    class Car{
        
        private double price;
        private int speed;
        
        Car(double price, int speed){
            //...
        }
    }
    
    // somewhere else in the code
    
    Car myCar = new Car(13.5, 200);
    
    class Car:
      
      def __init__(self, price, speed):
        self.__price = price # type: float
        self.__speed = speed # type: int
        
    
    # somewhere else in the code
    my_car = Car(13.5, 200);  
    


    Tools β†’ UML β†’ Object Diagrams β†’ Associations β†’

    What

    A solid line indicates an association between two objects.

    πŸ“¦ An example object diagram showing two associations:


    Activity Diagrams

    Introduction

    Tools β†’ UML β†’ Activity Diagrams β†’

    Introduction

    A UML Activity diagram (AD) can model workflows.

    An example activity diagram:

    [source:wikipeida]


    Basic Notations

    Tools β†’ UML β†’ Activity Diagrams β†’

    Linear Paths

    An activity diagram (AD) captures an activity of actions and control flows that makes up the activity.

    • An action is a single step in an activity. It is shown as a rectangle with rounded corners.
    • A control flow shows the flow of control from one action to the next. It is shown by drawing a line with an arrow-head to show the direction of the flow.

    Note the slight difference between the start node and the end node which represent the start and the end of the activity, respectively.

    πŸ“¦ This activity diagram shows the action sequence of the activity a passenger rides the bus:

    Which of these activity diagrams use the correct UML notation?

    • i
    • ii
    • iii
    • iv
    • v

    • i : πŸ‘ Correct. The arrow-head type does not matter.
    • ii : Incorrect. The start and end node notation is swapped.
    • iii : Incorrect. Action boxes should have rounded corners.
    • iv : πŸ‘ Correct. An activity can have only one action.
    • v : Incorrect. There cannot be any double-headed arrows.

    Tools β†’ UML β†’ Activity Diagrams β†’

    Alternate Paths

    A branch node shows the start of alternate paths. Each control flow exiting a branch node has a guard condition : a boolean condition that should be true for execution to take that path. Only one of the guard condition can be true at any time.

    A merge node shows the end of alternate paths.

    Both branch nodes and merge nodes are diamond shapes. Guard conditions must be in square brackets.

    πŸ“¦ The AD below shows alternate paths involved in the workflow of the activity shop for product:

    Which of these activity diagrams use the correct UML notation?

    • i
    • ii
    • iii
    • iv
    • v
    • vi

    • i : πŸ‘ Correct. There can be more than two alternate paths.
    • ii : πŸ‘ Correct. An alternate path can divide into more branches.
    • iii : πŸ‘ Correct. A branch can join other branches.
    • iv : Incorrect. At x=5 both guard conditions become true.
    • v : πŸ‘ Correct. It is fine for a branch to form a loop by going back to the original branch node.
    • iv : Incorrect. Guard conditions should be given in square brackets.

    Tools β†’ UML β†’ Activity Diagrams β†’

    Parallel Paths

    Fork nodes indicate the start of concurrent flows of control.

    Join nodes indicate the end of parallel paths.

    Both have the same notation: a bar.

    In a set of parallel paths, execution along all parallel paths should be complete before the execution can start on the outgoing control flow of the join.

    πŸ“¦ In this activity diagram (from an online shop website) the actions User browsers products and System records browsing data happen in parallel. Both of them need to finish before the log out action can take place.

    Which of these activity diagrams use the correct UML notation?

    • i
    • ii
    • iii
    • iv

    • i : πŸ‘ Correct. There can be more than two parallel paths.
    • ii : Incorrect. All parallel paths that started from a fork should end in the same join node.
    • iii : Incorrect. Parallel paths must end with a join node.
    • iv : πŸ‘ Correct. A parallel path can have multiple actions.

    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:


    🚧 Remaining weeks will be added incrementally over the semester.