플라이급 샘플 코드 http://www.oodesign.com/flyweight-pattern-wargame-example-java-sourcecode.html을 살펴보고 정적 인스턴스 (위의 사이트에서 SOLDIER
)를 정적이 아닌 병사에게 할당 할 때 실제로 작동하는 방법이 궁금합니다. 예를 들어 SoldierClient
에 우리가 실제로 각각의 SoldierClient
은 SOLDIER
의 사본을 보유 할 것이기 때문에 객체 크기를 줄이는 지 여부는 각 SoldierClient
개체에서 발생합니까?정적 인스턴스를 플라이 웨이트 패턴에 정적으로 할당하기
편집 : 방법에
는 moveSoldier()
는
//이
오시는 길 // 다음 새 위치에서 군인 표현을 렌더링 이전 위치
에서 군인 표현을 삭제 말한다 이 클래스에서 생성 된 모든 객체에는 영향을주지 않습니다. WarGame
package flyweight;
public class SoldierImp implements Soldier {
/**
* Intrinsic State maintained by flyweight implementation
* Solider Shape (graphical represetation)
* how to display the soldier is up to the flyweight implementation
*/
private Object soldierGraphicalRepresentation;
/**
* Note that this method accepts soldier location
* Soldier Location is Extrinsic and no reference to previous location
* or new location is maintained inside the flyweight implementation
*/
public void moveSoldier(int previousLocationX, int previousLocationY,
int newLocationX, int newLocationY) {
// delete soldier representation from previous location
// then render soldier representation in new location
}
+1 볼 수 있지만 내 혼란이 여기에 우리가 참조의 속성을 변경하면되고, 그것은 또한 정적 대응에 반영해야하지만,이 경우에는 그렇지 않습니다? – coder9
@ coder9 링크하는 코드는 절대 참조의 속성을 변경하지 않습니다. 사실 참조 *에는 속성이 없습니다. –
위와 같이 편집 한 질문입니다. 감사합니다 – coder9