Skip to content

Instantly share code, notes, and snippets.

@rain1024
Last active August 29, 2015 14:05
Show Gist options
  • Save rain1024/b0790df762260f0219af to your computer and use it in GitHub Desktop.
Save rain1024/b0790df762260f0219af to your computer and use it in GitHub Desktop.
uml

Association

image

public class Customer {
    private String name;
    private String address;
    private String contactNumber;
    }
 
    public class Car {
        private String modelNumber;
        private Customer owner;
   }

Agression

Paterns: <Chain of responsibility>

This shows “has a” relationship. It is a form of association relationship. This relationship highlights that a whole is made of its parts. So if a whole is destroyed the part still remains. In UML this is represented through a hollow diamond with the diamond symbol pointing towards the whole. In case of Java the aggregation follows the same structure as association. It is represented through the instance variables of a class.

image

public class Student {
}
public class School {
    private Student student;
}

Class Diagram

class

image

  • public +
  • private -
  • protected #
  • package ~
public class Employee {
    private static String department = "R&D";
    private int empId;
    private Employee(int employeeId) {
        this.empId = employeeId;
    }
    public static String getEmployee(int emplId) {
        if (emplId == 1) {
            return "idiotechie";
        } else {
            return "Employee not found";
        }
    }
    public static String getDepartment() {
        return department;
    }
}

Composition

This is again a whole or part relationship where if the whole is destroyed then the part cannot exist independently. Another important point about Composition is that the part at any point in time can have only one owner. E.g. A person can be an employee of one company at any point in time due to contractual obligations. That person cannot hold dual work authorisation. If the Company goes bankrupt the employee of this company does not exist and will be fired. The composition is represented as a filled diamond with data flowing in single direction from the whole to the part. The composition in Java is represented in the same form as aggregation with help of instance variables.

image

public class Employee {
}
 
public class Company {
    private Employee[] employee;
}

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment