Σημερινή παρουσίαση

of 107 /107
2009 ΟΠΑ -Τεχνολογία Λογισμικού – Εμμ. Γιακουμάκης 1 ΟΙΚΟΝΟΜΙΚΟ ΠΑΝΕΠΙΣΤΗΜΙΟ ΑΘΗΝΩΝ ΤΜΗΜΑ ΠΛΗΡΟΦΟΡΙΚΗΣ ΤΕΧΝΟΛΟΓΙΑ ΛΟΓΙΣΜΙΚΟΥ Λεπτομερής Σχεδίαση (2/2) Μανόλης Γιακουμάκης αναπληρωτής καθηγητής ΟΠΑ

Embed Size (px)

description

ΟΙΚΟΝΟΜΙΚΟ ΠΑΝΕΠΙΣΤΗΜΙΟ ΑΘΗΝΩΝ ΤΜΗΜΑ ΠΛΗΡΟΦΟΡΙΚΗΣ ΤΕΧΝΟΛΟΓΙΑ ΛΟΓΙΣΜΙΚΟΥ Λεπτομερής Σχεδίαση (2/2) Μανόλης Γιακουμάκης αναπληρωτής καθηγητής ΟΠΑ. Σημερινή παρουσίαση. Από το σχέδιο στον κώδικα Κλάσεις Απλοί τύποι Συσχετίσεις Κληρονομικότητα και διεπαφές Διαγράμματα ακολουθίας - PowerPoint PPT Presentation

Transcript of Σημερινή παρουσίαση

  • 2009 - . *

    (2/2)

    - .

  • 2009 - . * ,

    - .

  • , . UML , . , UML , .2009 - . *

    - .

  • public class Employee { private static int lastEmpId ; protected int Id; private String firstName; private String lastName; public final int maxNumberOfPhones = 2; private String[] phoneNumbers = new String[maxNumberOfPhones]; public String getFirstName() {} public void setFistName(String firstName) {} public String getLastName() {} public void setLastName(String lastName){} public void paySalary(Month month){} protected void calculateSalary(Month month) {} public static int nextEmployeeId(){} }

    2009* - .

    - .

  • , UML . UML Java, . UML. , UML, Java . (protected) Java (package).

    2009* - .

    - .

  • Java2009 - . *University a = new University();a.setName("AUEB");University b = a;

    - .

  • Java2009 - . *University a = new University();a.setName("AUEB");University b = new University();b.setName("AUEB);

    - .

  • Java2009 - . * , , . .

    - .

  • . 2009* - .

    - .

  • 2009 - . * :public class Book {private Publisher publisher;

    public void setPublisher(Publisher publisher) {this.publisher = publisher; }

    public Publisher getPublisher() { return publisher; }}

    - .

  • Book Publisher, publisher Publisher Book . 8-33. setPublisher getPublisher

    2009* - .

    - .

  • 2009 - . *public class Book { private Set items = new HashSet(); public Set getItems(){ return items; }}

    - .

  • Book Item. Java. Java Set , HashSet TreeSet.

    2009* - .

    - .

  • 2009 - . * . Book items . , .

    - .

  • items HashSet, HashSet getItems(). Set HashSet.

    2009* - .

    - .

  • Book , . (.. Set) (.. HashSet). , . items. items = new TreeSet() Book.2009* - .

    - .

  • , items, : Book oneBook = new Book(); Item oneItem = new Item(); oneBook.getItems().add(oneItem); oneBook.getItems().remove(oneItem); , oneBook oneItem. oneItem items .

    2009* - .

    - .

  • setItems Book, , . , : oneBook.setItems(null); , .2009* - .

    - .

  • , , . , Book : public class Book { // public void addItem(Item item) { if (item != null ) { items.add(item); } } public void removeItem(Item item) { if (item != null) { items.remove(item); } } }2009* - .

    - .

  • , : Set myItems = oneBook.getItems() myItems.add(aSecondItem) , . Book addItem removeItem. . getItems : public Set getItems(){ return new HashSet(items); }2009* - .

    - .

  • getItems items . , . .2009* - .

    - .

  • 2009 - . *

    - .

  • 8-36 . : Set myItems = oneBook.getItems(); myItems oneBook. myItems . . addItem removeItem.2009 - . *

    - .

  • : oneBook.addItem(oneItem); oneBook.getItems().add(secondItem); oneItem () items. secondItem items. items .2009 - . *

    - .

  • : public class Book { private Set items = new HashSet(); public Set getItems() { return new HashSet(items); } public void addItem(Item item) { if (item != null ) { items.add(item); } } public void removeItem(Item item) { if (item != null) { items.remove(item); } } } 2009 - . *

    - .

  • . . . . . .2009 - . *

    - .

  • 2009 - . *public class Item {private Book book;public Book getBook() {return book; } } public class Book {private Set items = new HashSet();public void addItem(Item item) {//}public void removeItem(Item item) {//}}

    - .

  • 2009 - . *

    - .

  • . Java . , . ( ) . 2009 - . *

    - .

  • 2009 - . *public class Car {Engine engine;public void drive() throws CarException {if (engine == null ) {throw new CarException(); }// } } . Engine Car. drive. , drive, , () .

    - .

  • / , . .2009 - . *

    - .

  • 2009 - . *public class Borrower {private Address address = new Address();public void setStreet(String street) {address.setStreet(street);} public String getStreet() {return address.getStreet(); }public void setNumber(String number) {address.setNumber(number); }public String getNumber() {return address.getNumber(); }// Address }

    - .

  • , . UML Java . UML Java Java . 2009 - . *

    - .

  • 2009 - . *

    - .

  • public interface Transport { public void move(); } public interface Vehicle extends Transport { public void drive(); } public abstract class AutoMobile implements Vehicle{ public void drive() { // AutoMobile drive } public void move() { // AutoMobile move } }2009 - . *

    - .

  • public class Car extends AutoMobile{ // Car drive. // drive } public class Truck extends AutoMobile{ // Truck drive. // drive } public class Boat implements Transport{ public void move() { // Boat move } } 2009 - . *

    - .

  • 2009 - . *

    - .

  • public class Order { private Set orderLines = new HashSet(); public int getTotal() { int total = 0; for(OrderLine orderLine : orderLines) { total += orderLine.getSubTotal(); } return total; } } public class OrderLine { private int quantity; private Product product; public int getSubTotal() { return product.getPrice(quantity); } } public class Product { private int price; public int getPrice(int quantity) { return price * quantity; } }2009 - . *

    - .

  • , , 2009 - . *

    - .

  • . . , . () . 2009 - . *

    - .

  • . . , . 2009 - . *

    - .

  • . (delegation) . , . , ( )2009 - . *

    - .

  • 2009 - . *

    - .

  • , . , . , . , , .2009 - . *

    - .

  • 2009 - . *

    - .

  • 2009 - . *

    - .

  • 2009 - . *

    - .

  • . . , . - .2009 - . *

    - .

  • - - - . , , . . .2009 - . *

    - .

  • . , . . . , .2009 - . *

    - .

  • 2009 - . *Bird bird = new Penguin();bird.fly();

    - .

  • 8-46 - . Bird fly. Penguin fly. fly Penguin . . . Penguin Bird, fly Bird, .2009 - . *

    - .

  • 2009 - . * Square Rectangle - , .

    - .

  • public class Rectangle { private int width; private int length; public void setWidth(int width) { this.width = width; } public int getWidth() { return width; } public void setLength(int length) { this.length = length; } public int getLength() { return length; } } 2009 - . *

    - .

  • public class Square extends Rectangle { public void setWidth(int width) { super.setWidth(width); super.setLength(width); } public void setLength(int length) { super.setWidth(length); super.setLength(length); } }

    setWidth setLength Square, . , .2009 - . *

    - .

  • : Rectangle myRectangle = new Rectangle(); myRectangle.setLength(5); myRectangle.setWidth(10); System.out.println("Length = " + myRectangle.getLength()); System.out.println("Width = "+ myRectangle.getWidth()); Square mySquare= new Square(); mySquare.setLength(5); mySquare.setWidth(10); System.out.println("Length = " + mySquare.getLength()); System.out.println("Width = "+ mySquare.getWidth());2009 - . *

    - .

  • 5 10 , 10 . . : Rectangle myRectangle = new Square(); myRectangle.setLength(5); myRectangle.setWidth(10); System.out.println("Length = " + myRectangle.getLength()); System.out.println("Width = "+ myRectangle.getWidth());2009 - . *

    - .

  • Rectangle Square. 5 10. Square , 10.2009 - . *

    - .

  • . . (design by contract) Meyer [Meyer 97]. 2009 - . *

    - .

  • (assertions) : (preconditions). . . (postconditions). . (invariants). . , , .2009 - . *

    - .

  • , . , , . Square . .2009 - . *

    - .

  • . . . . , . 2009 - . *

    - .

  • : . . . Square, Rectangle, .2009 - . *

    - .

  • . [McConnell 04, Riel 96]: . .2009 - . *

    - .

  • . . . , .2009 - . *

    - .

  • . , . . . 2009 - . *

    - .

  • , . , . 2009 - . *

    - .

  • . , , .. .2009 - . *

    - .

  • (conditional logic). . ( if switch) , . 2009 - . *

    - .

  • : if switch . , Java instancef . , . if switch .2009 - . *

    - .

  • if : if ( shape instanceof Rectangle ) { shape.drawRectangle(); } else { shape.drawCircle(); } instanceof Java , . .2009 - . *

    - .

  • switch (shape.type) { case Shape.RECTANGLE: shape.drawRectangle(); break; default: shape.drawCircle(); }

    . draw Shape Rectangle Circle .2009 - . *

    - .

  • . (collaboration) . . . . .2009 - . *

    - .

  • . , . : .2009 - . *

    - .

  • . . . .2009 - . *

    - .

  • . . , . 2009 - . *

    - .

  • , . . .2009 - . *

    - .

  • 2009 - . *

    - .

  • 2009 - . *

    - .

  • . , . . , : . .2009 - . *

    - .

  • , : ) , ) ) . . . . , .2009 - . *

    - .

  • UML2009 - . *

    - .

  • 2009 - . *

    - .

  • 2009 - . *

    - .

  • 2009 - . *

    - .

  • 2009 - . *

    - .

  • [McConnell 04, Riel 96, Wirfs-Brock 02]. : . .2009 - . *

    - .

  • . . , . , .2009 - . *

    - .

  • . . , .2009 - . *

    - .

  • 2009 - . *

    - .

  • 2009 - . *

    - .

  • 8-56.public class Borrower { private BorrowerCategory category; public BorrowerCategory getCategory() { return category; } public boolean canBorrow() { int pendingItems; if (getCategory() == null ) { return false; } 2009 - . *

    - .

  • pendingItems = countPendingItems(); return getCategory().canBorrow(pendingItems); } } public class BorrowerCategory { private int maxLendingItems; public boolean canBorrow(int pendingItems) { return maxLendingItems > pendingItems; } }2009 - . *

    - .

  • 2009 - . *

    - .

  • 2009 - . *

    - .

  • .public class Item { public Loan borrow(Borrower borrower) { if (borrower == null ) { return null; } if (!borrower.canBorrow()) { return null; } Loan loan = new Loan(); loan.setItem(this); loan.setBorrower(borrower); loan.setLoanDate(Calendar.getInstance()); return loan; } }2009 - . *

    - .

  • 2009 - . *

    - .

  • . . . . 2009 - . *

    - .

  • . (deployment) .. jar dll. . .2009 - . *

    - .

  • 2009 - . * , .

    - .

  • 2009 - . * 8-61 banking Transaction. Deposit Withdrawal banking.

    - .

  • . . , : .2009 - . *

    - .

  • . . , . (class libraries).2009 - . *

    - .

  • 2009 - . *

    - .

  • . . UML. 2009 - . *

    - .

  • 2009 - . *

    - .

  • 2009 - . *

    - .