Proxy 패턴은 뭘까? 서버에서 들었던 것 같은데, 패턴으로는 어떤 의미가 있는지 알아보자.
public final class Image {
private ImageData image;
// 생성시 이미지를 로드
public Image(String filePath) {
this.image = ImageLoader.getInstance().load(filePath);
}
public void draw(Canvas canvas, float x, float y) {
canvas.draw(this.image, x, y)
}
}
public final class Image {
private String filePath;
private ImageData image;
public Image(String filePath) {
this.filePath = filePath;
}
public void draw(Canvas canvas, float x, float y) {
if (this.image == null) {
this.image = ImageLoader.getInstance().load(this.filePath);
}
canvas.draw(this.image, x, y);
}
}
즉시 로딩 | 지연 로딩 + 캐시 X | 지연 로딩 + 캐시 (프록시 패턴) | |
---|---|---|---|
최신 데이터 | X | O | △ |
메모리 사용량 | 최대 | 최소 | 중간 (사용한 것에 대해 캐싱으로 들고 있음) |
실행 속도 병목점 | 생성 시점 | 사용할 때 마다 | 알기 어려움 (처음 사용한 시점에 발생) |
public final class Image {
private String filePath;
private ImageData image;
public Image(String filePath) {
this.filePath = filePath;
}
public boolean isLoaded() {
return this.image != null;
}
public void load() {
if (this.image == null) {
this.image = ImageLoader.getInstance().load(this.filePath);
}
}
public void unload() {
this.image = null;
}
public void draw(Canvas canvas, float x, float y) {
canvas.draw(this.image, x, y);
}
}
filePath
만 받는다.isLoaded()
)를 파악 할 수 있게 열어준다.load()
함수를 열어주어 제어할 수 있도록 한다.unload()
함수도 제공한다.draw()
함수의 경우 image
가 있다는 전제하에 작동한다.이 기사를 읽는 것은 독자가 필요로 하는 것을 진정으로 이해하는 사람과 함께 앉아 있는 것과 같았습니다. 당신의 글은 명확하고 https://avatarworldgame.com 위안이 되며 주의와 인내로 각 아이디어를 안내합니다. 글쓰기에서 이처럼 전문성과 공감의 균형 잡힌 조합을 찾는 것은 드문 일이며, 이는 진정으로 풍요로운 경험을 선사했습니다.
오~ 프록시 패턴부터 시작해서 웹 성능 최적화, 안드로이드 이미지 최적화까지! 진짜 개발하면서 필요한 내용들 꽉꽉 담았네. 한번 쭈욱 읽어봐야겠다!@chill guy clicker
subway surfers online I'm captivated by how this article seamlessly weaves together seemingly unrelated topics into a cohesive narrative.