비지니스 로직의 개발

1. Inventory Management System의 business case review

validation rule :

The maximum increase is limited to 50%.

The minimum increase must be greater than 0%.

클래스 다이어그램

사용자 삽입 이미지

2. 비즈니스 로직에 몇 개의 클래스를 추가

2-1. 서비스 객체를 위해 service패키지를 도메인 객체를 위해 domain패키지를 생성한다.
src/springapp/domain
src/springapp/domain

2-1. 위의 클래스 다이어그램을 기준으로 product 클래스를 생성한다.

package springapp.domain;

import java.io.Serializable;

public class Product implements Serializable {

    private String description;
    private Double price;
    
    public String getDescription() {
        return description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
    
    public Double getPrice() {
        return price;
    }
    
    public void setPrice(Double price) {
        this.price = price;
    }
    
    public String toString() {
        StringBuffer buffer = new StringBuffer();
        buffer.append("Description: " + description + ";");
        buffer.append("Price: " + price);
        return buffer.toString();
    }
}
2-2. 단위 테스트를 생성한다.

springapp/test/springapp/domain/ProductTests.java

package springapp.domain;

import junit.framework.TestCase;

public class ProductTests extends TestCase {

    private Product product;

    protected void setUp() throws Exception {
        product = new Product();
    }

    public void testSetAndGetDescription() {
        String testDescription = "aDescription";
        assertNull(product.getDescription());
        product.setDescription(testDescription);
        assertEquals(testDescription, product.getDescription());
    }

    public void testSetAndGetPrice() {
        double testPrice = 100.00;
        assertEquals(0, 0, 0);    
        product.setPrice(testPrice);
        assertEquals(testPrice, product.getPrice(), 0);
    }
  
}
2-3. Product 클래스를 취급하는 ProductManager를 생성한다.
      이 인터페이스는 가격을 증가시키는 increasePrice(), product를 getter하기 위한
      getProducts() 메소드를 가진다.

src/springapp/service/ProductManager.java

package springapp.service;

import java.io.Serializable;
import java.util.List;

import springapp.domain.Product;

public interface ProductManager extends Serializable{

    public void increasePrice(int percentage);
    
    public List<Product> getProducts();
    
}

다음으로 계속......



























'개발 > 스프링' 카테고리의 다른 글

스프링 tutorial (6)  (0) 2008.07.26
스프링 tutorial (5)  (0) 2008.07.25
스프링 tutorial (3)  (0) 2008.07.17
스프링 tutorial (2)  (0) 2008.07.16
스프링 tutorial (1)  (0) 2008.07.16
Posted by 무혹
,