[SWM] Day1: OO concepts

Software Maintenance 1

3 main categories of maintenance

Corrective maintenance

  • Fixing errors in the system
  • e.g. Bugs

Adaptive maintenance

  • Modifying due to changes in the environment of the software
  • e.g. new laws, change of business needs

Perfective/performance maintenance

  • Improving system without changing its functionality
  • e.g. improving performance, ease of maintenance

What do you need to know to do maintenance?

  • Understanding the client
  • Understanding the code
  • Refactoring the code
  • Extending the code
  • Working as a team
  • Managing client expectations
  • Managing maintenance process

Useful OO concepts

Abstraction: concentrating only on essential characteristics; allows complexity to be more easily managed
Inheritance: One object acquires the properties of another; information is made manageable in a hierarchical order
Encapsulation: Hiding internal state and requiring all interaction to be performed through an object’s methods
Modularity: The source code for an object can be written and maintained independently of the source code for other objects
Polymorphism: Allows different classes to have different implementations of the same methods(overload, override)

Class Diagram

enter image description here
relationship: Generalisation(“is a” relationship)
-Implemented by inheritance

When extending the code, how do you know you haven’t broken it?

  • Regression testing
  • Re-running tests to check everything still works
  • Unit testing pays off here

Managing maintenance process

As a group, how then can we manage the design and implementation of changes?
  • Team meetings and a design process -e.g. Scrum
  • Team communication
  • Source code management(e.g. git)
  • Server-side testing(Continuous integration server)
What are the general rules for constructors, methods, helper methods, fields, and static constants?
  • Constructors and methods are usually declared public
  • Helper methods that are needed only inside the class are usually declared private
  • Fields are usually declared private(to support encapsulation)
  • Static constants are usually declared public

Constructors

A constructor is a procedure for creating objects of the class
  • A constructor often initializes an object’s fields
  • Constructors do not have a return type and they do not return a value
  • All constructors in a class have the same name(the name of the class)
  • Constructors may take parameters
  • If a class has more than one constructor, they must have different numbers and/or types of parameters(constructor overloading)
  • If you don’t define any constructors, Java provides a default constructor for each class which allocates memory and sets fields to the default values
  • If you define constructors for a class, Java does not provide a default constructor for that specific class - it needs to be explicitly re-defined

Passing parameters

  • Primitive data types are always passed “by value”: the value is copied into the parameter.
  • Objects are always passed as references: the reference is copied, not the object
  • Inside a method, “this” refers to the object for which the method was called. “this” can be passed to other constructors and methods as a parameter.

overloaded methods

  • Methods of the same class that have the same name but different numbers or types of parameters are called overloaded methods
  • The complier treats overloaded methods as completely different methods
  • The complier knows which one to call based on the number and the types of the parameters passed to the method
  • The complier knows which one to call based on the number and the types of the parameters passed to the method
  • The return type alone is not sufficient for making a distinction between overloaded methods

Collections

Core collection framework interfaces

  • Iterable: represents an iterator object
  • Collection: represents a group of objects(elements)
  • Map: maps keys to values(no duplicate keys)
  • Queue: represents FIFO queues or LIFO stacks
  • Deque: represents a double ended queue
  • Set: a collection that cannot contain duplicate elements
  • List: an ordered sequence of elements(allows duplicate elements)

Aggregation and Composition

Aggregation

The object exists outside the other, is created outside, so it is passed as an argument to the constructor
“has a” relationship

Composition

The object only exists, or only make sense inside the other, as a part of the other.
also “has a” relationship, but the class is responsible for another class, like when class A is terminate, class B also terminate.

What is the difference between an abstract class and an interface

  • An interface is a contract/ an interface is an empty shell
  • Interfaces are less restrictive when it comes to inheritance

Examples of basic maintenance


  • Dividing all classes into packages
Packages are used in Java in order to prevent naming conflicts, to control access, to make searching/locating and usage of classes, interfaces, etc.
providing access protection and name space management

  • Making all animal subclasses abstract
  • Removing redundant code(removing some setters)
  • Commenting code and producing Javadocs
  • Default access control and initialization

    Local variables

    There is no default value for local variable, so local variables should be declared and an initial value should be assigned before the first use.
    enter image description here

    instance variables

    default value: false, 0, null
    The default access modifier is “package private”, which means that it may be access from any other class in the same package as the declaring class.

    Static variables

    default value: false, 0, null
    Static variables are either initialised when declared or it is done in a specific static initialisation block.

    Basic Maintenance–Javadocs

    Adding database access

    • The interface for accessing relational database from Java is Java Database Connectivity(JDBC)
    • Via JDBC you create a connection to the database, issue database queries and update as well as receive the results
    • To connect to MySQL from Java, you have to use the JDBC driver from MySQL
    • Create a **lib**folder and copy the JDBC driver into this folder
    • Add the JDBC driver to your “BuildPath”
      enter image description here

    Use Case Driven OOA/D Process

    enter image description here

    UML

    UML(Unified Modelling Language) is a family of graphical notations that help in describing, designing and organising object oriented software systems
    Advantages of using UML
    • Enhances communication and ensures the right communication
    • Captures the logical software architecture independent of the implementation language
    • Helps to manage the complexity
    • Enables reuse of design

    Use Case Diagrams

    • Behaviour diagrams used to describe a set of actions(use cases) that some system or systems(subject) should or can perform in collaboration with one or more external users of the system(actors)
    • They do not make any attempt to represent the order or number of times that the systems actions and sub-actions should be executed
    User case diagram components:
    - Actors
    - Use cases
    - System boundary
    - Relationship
    Actors: Entities that interface with the system
    Can be people or other systems
    Think of actors by considering the roles they play
    Use cases: Based on user stories (derived from discussions with stakeholders)
    Represent what the actor wants your system to do for them
    In the use case diagram only the use case name is represented; in a use case specification each use case is formally described
    Relationship between use case and actor:
    Associations indicate which actors initiate which use cases
    Relationship between two use cases:
    Specifying common functionality and simplifying use case flows
    Using <<include>> or <<extend>>
    <<include>>
    -Multiple use case share a piece of same functionality which is placed in a separate use case rather than documented in every use case that needs it.
    -One use case is a functionality that another use case requires
    -The dependent use case ultimately re-uses the depended-on use case
    <<extends>>
    -Use when activities might be performed as part of another activity but are not mandatory for a use case to run successfully
    -We are adding more capability
    

    评论

    此博客中的热门博文

    [MLE] W2 Multivariate linear regression

    [MLE] W1 Introduction

    [AIM] MetaHeuristics