pinkred's mobile program

pinkred mobile programer

코드로 대화하기 – 목적을 분명하게 밝혀라~!

leave a comment »

목적을 분명하게 밝혀라~!

코드에는 목적을 분명히 노출 해줄수 있도록 해야한다.

class Cart
{
    public List cartList;

    public Cart()
    {
        cartList = new ArrayList();
    }
}

 


class Cart
{
    private List<String> cartList;

    public Cart()
    {
        cartList = new ArrayList();
    }

    public void addItem(String item)
    {
        if(item == null || item.isEmpty() == true)
        {
            throw new EmptyItemException("item == null || item.isEmpty() == true");
        }

        cartList.add(item);
    }

    public void addAllItem(List<String> cartList)
    {
        if(cartList == null || cartList.size() == 0)
        {
            throw new EmptyItemException("item == null || item.isEmpty() == true");
        }

        this.cartList.addAll(cartList);
    }
}

위의 코드를 보면 cartList의 값을 public로 하여 모든 것을 다 허용해 주겠어라는 식의 대화법을 나타냈다.

난 너를 위해 모든것을 다 줄수 있다는 대화법으로 잘 이용하면 좋지만 잘못 이용하면 난장판이 될수 도 있고 어떻게 관계를 이어가는데도 쉽지 않을수 있다.

아래 코드는 나와 대화하기 위해서는 특정 통로 로만 접근이 가능해. 그리고 지켜야할 약속들이 있어라고 말하고 있다.

어떻게 보면 밀당 같지만 너와 나와의 연결고리를 확실히 하고 있다.

목적이 무엇인지를 생각해보자.

Written by pinkredmobile

2018/03/16 , 시간: 9:19 am

프로그래밍(programming)에 게시됨

Tagged with ,

댓글 남기기