본문 바로가기

프로그래밍/미분류

프로토타입 패턴은 왜 사용하는 건가?

반응형

http://stackoverflow.com/questions/13887704/whats-the-point-of-the-prototype-design-pattern


질문 : 프로토타입 패턴은 왜 사용하는 건가?

What's the point of the Prototype design pattern?


http://stackoverflow.com/a/13888045/100093


프로토타입 패턴은 예를 들면 다음과 같은 잇점이 있다.


 - 객체 초기화 때의 (매우 비쌀 가능성이 있는) 오버헤드를 없애준다.

 - 같은 타입의 여러 객체가 거의 유사한 데이터를 가지고 있는 유스케이스를 최적화한다.


예를 들어, 프로그램이 네트워크로부터 거의 변하지 않는 데이터를 파싱하여 객체를 만든다고 하자. 객체를 만들 때마다 데이터를 매번 파싱하는 대신에, 프로토타입 패턴을 사용하여 이미 있는 객체를 복사하여 새로운 객체를 만들어 낼 수 있다.


더불어 객체가 이미지 같은 매우 큰 메모리를 차지한다고 할 때도 유용하다고... 블라블라.


The prototype pattern has some benefits, for example:


It eliminates the (potentially expensive) overhead of initializing an object

It simplifies and can optimize the use case where multiple objects of the same type will have mostly the same data

For example, say your program uses objects that are created from data parsed from motley unchanging information retrieved over the network. Rather than retrieving the data and re-parsing it each time a new object is created, the prototype pattern can be used to simply duplicate the original object whenever a new one is needed.


Also, say that object may have data that uses up large amounts of memory, such as data representing images. Memory can be reduced by using a copy-on-write style inheritance, where the original, unduplicated data is shown until the code attempts to change that data. Then, the new data will mask to reference to the original data.


marcus erronius

728x90

'프로그래밍 > 미분류' 카테고리의 다른 글

부동소수점 연산  (0) 2016.08.18
Property-based Testing  (0) 2016.07.16
electrons on sphere  (0) 2015.11.18
IPv6 주소 뒤의 퍼센트 기호의 의미는?  (0) 2015.10.28
Teredo 터널 어댑터란? ISATAP 란?  (0) 2015.10.27