UML Visibility UML Notation Atributes Methods Java visibility
Απεικονίσεις UML και σύμβολα Visibility UML Notation Atributes Methods Java visibility UML Notation public + # ~ private Protected package Παναγιώτης Σφέτσος, Μηχανική Λογισμικού ΙΙ 9
Συσχέτιση – Association (2/4) class Company { Employee emp[]= new Employee[4]; public void set. Employee(Employee e, int a) {emp[a]=e; } public void print. All() { for (int i=0; i<4; i++) { System. out. println("Name = "+ emp[i]. get. Name()); System. out. println("Type Of Employment = "+ emp[i]. get. Emp. Type()); System. out. println("Type Of Payment = "+ emp[i]. get. Pay. Type()); System. out. println(); emp[i]. calc. Salary(); } } } abstract class Employee { String name; protected int pay. Type; protected int b; protected int h; Employee(String s, int b_, int h_, int p) {name=s; pay. Type=p; b=b_; h=h_; } public String get. Name() {return name; } public String get. Pay. Type() { String p. Type; if (pay. Type==0) p. Type="Salary"; else p. Type="By. Hour"; return p. Type; } abstract String get. Emp. Type(); Παναγιώτης Σφέτσος, abstract void calc. Salary(); } Πολλαπλότητα Μηχανική Λογισμικού ΙΙ 13
Συσχέτιση – Association (3/4) Συσχέτιση μονής κατεύθυνσης (unidirectional association) public class Customer { private String name; private String address; private String contact. Number; } public class Car { private String model. Number; private Customer owner; } Παναγιώτης Σφέτσος, Μηχανική Λογισμικού ΙΙ 14
Συσχέτιση – Association (4/4) Συσχέτιση διπλής κατεύθυνσης (bidirectional association) public class Customer { private String name; private String address; private String contact. Number; private Car car; } public class Car { private String model. Number; private Customer owner; } Παναγιώτης Σφέτσος, Μηχανική Λογισμικού ΙΙ 15
Γενίκευση – Κληρονομικότητα (2/3) public String get. Pay. Type() { String p. Type; if (pay. Type==0) p. Type="Salary"; else p. Type="By. Hour"; return p. Type; } abstract String get. Emp. Type(); abstract void calc. Salary(); } class Administrator extends Employee { Administrator(String s, int b, int h, int p) {super(s, b, h, p); } public String get. Emp. Type() {return "Administrator"; } public void calc. Salary() { int s=0; if (pay. Type==0) s=1200+b; else s=(h*12); System. out. println(" Sarary = " + s); }} Παναγιώτης Σφέτσος, Μηχανική Λογισμικού ΙΙ 17
Γενίκευση – Κληρονομικότητα (3/3) class Technical extends Employee { public Technical(String s, int b, int h, int p) {super(s, b, h, p); } public String get. Emp. Type() {return "Technical"; } public void calc. Salary() { int s=0; if (pay. Type==0) s=800+b; else s=(h*10); System. out. println(" Sarary = " + s); } } Παναγιώτης Σφέτσος, Μηχανική Λογισμικού ΙΙ 18
Visual Paradigm - Παράδειγμα (1/7) Έστω ο κώδικας: abstract class Employee { String name; protected int pay. Type; protected int b; protected int h; Employee(String s, int b_, int h_, int p) {name=s; pay. Type=p; b=b_; h=h_; } public String get. Name() {return name; } public String get. Pay. Type() { String p. Type; if (pay. Type==0) p. Type="Salary"; else p. Type="By. Hour"; return p. Type; } abstract String get. Emp. Type(); abstract void calc. Salary(); } Παναγιώτης Σφέτσος, Μηχανική Λογισμικού ΙΙ 25
Visual Paradigm - Παράδειγμα (2/7) class Administrator extends Employee { Administrator(String s, int b, int h, int p) {super(s, b, h, p); } public String get. Emp. Type() {return "Administrator"; } public void calc. Salary() { int s=0; if (pay. Type==0) s=1000+b; else s=(h*12); System. out. println(" Sarary = " + s); }} class Technical extends Employee { public Technical(String s, int b, int h, int p) {super(s, b, h, p); } public String get. Emp. Type() {return "Technical"; } public void calc. Salary() { int s=0; if (pay. Type==0) s=800+b; else s=(h*10); System. out. println(" Sarary = " + s); } } Παναγιώτης Σφέτσος, Μηχανική Λογισμικού ΙΙ 26
Visual Paradigm - Παράδειγμα (3/7) class Company { Employee emp[]= new Employee[4]; public void set. Employee(Employee e, int a) {emp[a]=e; } public void print. All() { for (int i=0; i<4; i++) { System. out. println("Name = "+ emp[i]. get. Name()); System. out. println("Type Of Employment = "+ emp[i]. get. Emp. Type()); System. out. println("Type Of Payment = "+ emp[i]. get. Pay. Type()); System. out. println(); emp[i]. calc. Salary(); } } } class Ask 1 { public static void main(String[] args) { int a; Employee e 1= new Technical("Nikas", 10, 0); Employee e 2=new Administrator("Vasileiou", 10, 1); Employee e 3= new Technical("Paylidis", 10, 1); Employee e 4=new Administrator("Apostolatos", 10, 0); Company c = new Company(); Παναγιώτης Σφέτσος, Μηχανική Λογισμικού ΙΙ c. set. Employee(e 1, 0); c. set. Employee(e 2, 1); c. set. Employee(e 3, 2); c. set. Employee(e 4, 3); c. print. All(); } } 27
- Slides: 37