2017-10-08 11 views
0

간단한 Java 프로그램에 대한 시퀀스 다이어그램을 만드는 중급 임무를 수행하려고합니다. 그러나 어떤 요소를 다이어그램에 넣고 어떤 요소를 생략할지 결정할 수없는 문제가 발생했습니다. 나는 그것이 질문에 대답하는 데 도움이 될 수 있다면 JAVA 코드를 게시하고 있습니다.UML 2.0 시퀀스 다이어그램 깊이

public class TestPOS { 
public static void main(String[] args) { 
    // POST 객체를 준비 
    Store store = new Store(); 
    ProductCatalog catalog = new ProductCatalog(); 
    catalog.addSpec(1, new ProductSpec(1, "pencil", 1000)); 
    catalog.addSpec(2, new ProductSpec(2, "eraser", 500)); 
    catalog.addSpec(3, new ProductSpec(3, "fountain pen", 50000)); 
    POST post = new POST(store, catalog); 

    // 첫 번째 판매 
    post.enterItem(1, 12); 
    post.enterItem(2, 4); 
    post.enterItem(3, 1); 

    post.makePayment(); 

    post.endSale(); 

    // 두 번째 판매 
    post.enterItem(1, 2); 
    post.enterItem(2, 1); 

    post.makePayment(); 

    post.endSale(); 

    // 출력을 보여주어 이해를 돕기위한 코드 
    for (Sale sale : store.completedSales) { 
     System.out.println(sale.getDate()); 
     sale.printLineItems(); 
     System.out.println("total = " + sale.getTotal()); 
    } 
    } 
} 

enterItem(), makePayment() 및 endSale()을 호출하는 곳입니다. 할당은 위의 세 함수에 대한 시퀀스 다이어그램을 만드는 것입니다. 아래에 각 반을 게시 할 것입니다.

----------------------------------------------------------- 
import java.util.Date; 
public class POST { 
    private Store store; 
    private ProductCatalog catalog; 
    private Sale sale = null; 

    public POST(Store store, ProductCatalog catalog) { 
     this.store = store; 
     this.catalog = catalog; 
    } 

    public void enterItem(int upc, int qty) { 
     if (sale == null) { 
      Date date = new Date(System.currentTimeMillis()); 
      sale = new Sale(date); 
     } 
     ProductSpec s = catalog.spec(upc); 
     sale.makeLineItem(s, qty); 
    } 

    public void makePayment() { 
     if (sale != null) sale.makePayment(); 
    } 

    public void endSale() { 
     store.addCompleteSale(sale); 
     sale = null; 
    } 
} 
----------------------------------------------------------- 
import java.util.ArrayList; 
public class Store { 
    protected ArrayList<Sale> completedSales = null; 

    public Store() { 
     completedSales = new ArrayList<Sale>(); 
    } 

    public void addCompleteSale(Sale sale) { 
     completedSales.add(sale); 
    } 
} 
----------------------------------------------------------- 
import java.util.ArrayList; 
import java.util.Date; 
public class Sale { 
    private Date date; 
    private ArrayList<SalesLineItem> lineItem = null; 
    private Payment payment = null; 

    public Sale(Date date) 
    { 
     this.date = date; 
     lineItem = new ArrayList<SalesLineItem>(); 
    } 

    public void makeLineItem(ProductSpec s, int qty) { 
     SalesLineItem item = new SalesLineItem(s, qty); 
     lineItem.add(item); 
    } 

    public int getTotal() { 
     int total = 0; 
     for (SalesLineItem item : lineItem) { 
      total += item.getSubTotal(); 
     } 
     return total; 
    } 

    public void makePayment() { 
     int total = this.getTotal(); 
     payment = new Payment(total); 
    } 

    // 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음 
    public Date getDate() { 
     return date; 
    } 

    // 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음 
    public void printLineItems() { 
     for (SalesLineItem item : lineItem) { 
      System.out.println("upc : " + item.getItemUpc() +", name : " + item.getItemName() + ", price : " 
        + item.getItemPrice() + ", quantity : " + item.getQuantity()); 
     } 
    } 
} 
----------------------------------------------------------- 
public class Payment { 
    private int amount; 

    public Payment(int amount) { 
     this.amount = amount; 
    } 

    // 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음 
    public int getAmount() { 
     return amount; 
    } 
} 
----------------------------------------------------------- 
public class SalesLineItem { 
    private int quantity; 
    private ProductSpec spec; 

    public SalesLineItem(ProductSpec spec, int quantity) { 
     this.spec = spec; 
     this.quantity = quantity; 
    } 

    public int getSubTotal() { 
     int price = spec.getPrice(); 
     return price * quantity; 
    } 

    // 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음 
    public int getItemUpc() { 
     return spec.getUpc(); 
    } 

    // 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음 
    public String getItemName() { 
     return spec.getName(); 
    } 

    // 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음 
    public int getItemPrice() { 
     return spec.getPrice(); 
    } 

    // 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음 
    public int getQuantity() { 
     return quantity; 
    } 
} 
----------------------------------------------------------- 
import java.util.HashMap; 
public class ProductCatalog { 
    private HashMap<Integer, ProductSpec> specTable = new HashMap<Integer, ProductSpec>(); 

    public void addSpec(int upc, ProductSpec spec) { 
     specTable.put(upc, spec); 
    } 

    public ProductSpec spec(int upc) { 
     return specTable.get(upc); 
    } 
} 
----------------------------------------------------------- 
public class ProductSpec { 
    private int upc; 
    private String name; 
    private int price; 

    public ProductSpec(int upc, String name, int price) { 
     this.upc = upc; 
     this.name = name; 
     this.price = price; 
    } 

    public int getPrice() { 
     return price; 
    } 

    // 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음 
    public int getUpc() { 
     return upc; 
    } 

    // 출력을 보여주어 이해를 돕기위한 메소드, 클래스 다이어그램에 반영하지 않음 
    public String getName() { 
     return name; 
    } 
} 

코드에 한국어는 신경 쓰지 않아도됩니다. 이제 아래의 그림은 내가 옳은 것인지 아닌지에 대한 다이어그램입니다.

enterItem sequence diagram

주요 문제

내가 종료에 방법에 사용되는 모든 요소의 상호 작용 및 인스턴스를 그릴해야하는지 실마리를 필요가 없다는 것입니다. 나는 약간 조직화되지는 않았지만 다른 누군가가 내 문제를 해결해주기를 바랍니다.

답변

1

도면이 정확한지 여부를 사용자가 직접 확인하지 않았습니다. ProductSpec을 작성하면 POST으로 곧바로 돌아갑니다. 그것은 당신의 맥락에서 합법적 인 약어 일지 모르지만 코드를 반영하지는 않을 것입니다.

어쨌든 SD에 넣은 내용은 특정 상황을 명확히하고 분명하게 이해해야합니다. 모든 것을 단일 SD에 저장하는 것은 결코 좋은 생각이 아닙니다. 메인 플로우를 강조하는 대략적인 개요를 작성하십시오. POS 시스템에서 이것은 아마도 처음에는 두 가지 일 것입니다 : 전체 물건의 초기화와 카탈로그의 기사 입력. SD를 두 개 만들면된다는 뜻입니다. 또한 "그래픽으로 프로그래밍"하고 여러 조각을 한꺼번에 사용하도록 유혹해서는 안됩니다. 코드에서 찾은 if 또는 case이 아닌 중요한 경로 결정 등을 위해 두십시오. SDs의 관점에서 보면 더 자주 사용하는 것이 좋습니다.

참고 : 선생님 께서 의도하신 내용을 모르겠습니다. 제 성명서와 모순 될 수 있습니다. 그리고 그는 당신에게 쓸데없는 벽 종이를 만들어달라고합니다.