Ramifications

[Previous] [Next]

Sharing a single instance of a class is cost effective because a single instance doesn't depreciate the available memory, which is a finite resource. Also, the overhead of constructing an instance of the class occurs only when the initial request is made. The Singleton design pattern controls the instantiation of the target class, so the client can't violate its intent.

You can extend the Singleton design pattern to support multiple instances of the target class when this solution is warranted. For example, you can extend the Singleton design pattern so that instead of creating a single database connection object that connects to a particular database, the design pattern implementation will create unique database connection objects for several distinct databases. The only requirement is that you must modify the implementation of the CreateInstance method of the TargetFactory class. If you have scenarios that each require different behavior, you can design TargetFactory as an interface that concrete TargetFactory classes can implement, thus providing the benefit of polymorphism.



Microsoft Visual Basic Design Patterns
Microsoft Visual Basic Design Patterns (Microsoft Professional Series)
ISBN: B00006L567
EAN: N/A
Year: 2000
Pages: 148

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net