Move Method


A method is, or will be, using or used by more features of another class than the class on which it        is defined.

Create a new method with a similar body in the class it uses most. Either turn the old method into a simple delegation, or remove it altogether.

  

For more information see page 142 of Refactoring

Additional Comments


Marian Vittek sent an example  for moving a method to a method argument.

class Project {
  Person[] participants;
}

class Person {
  int id;
  boolean participate(Project p) {
    for(int i=0; i           if (p.participants[i].id == id) return(true);
    }
    return(false);
  }  
}

... if (x.participate(p)) ...


After applying the move you end up with


class Project {
  Person[] participants;
  boolean participate(Person x) {
    for(int i=0; i           if (participants[i].id == x.id) return(true);
    }
    return(false);
  }  
}

class Person {
  int id;
}

... if (p.participate(x)) ...



He also points out that the part of the Move Method mechanics that reads Determine how to reference the correct target object from the source, should be replaced by Determine how to reference the correct
target object from the source or from arguments of the method
which is more general.



***** 아름다운프로님에 의해서 게시물 복사 + 카테고리변경되었습니다 (2003-12-18 17:27)
Posted by 아름프로
BLOG main image

카테고리

분류 전체보기 (539)
이야기방 (19)
토론/정보/사설 (16)
IBM Rational (9)
U-IT (0)
SOA/WS/ebXML (110)
개발방법론/모델링 (122)
J2SE (34)
J2EE (60)
DataBase (39)
Open Projects (30)
BP/표준화 (50)
Apache Projects (15)
Web/보안/OS (22)
Tools (7)
AJAX/WEB2.0 (1)
Linux/Unix (1)
영어 (0)
비공개방 (0)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

달력

«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28

글 보관함

Total :
Today : Yesterday :