Dispose pattern: Difference between revisions

Content deleted Content added
Libnoon (talk | contribs)
Resource management is always manual: not specific to the Dispose pattern.
Libnoon (talk | contribs)
Only open files have a file descriptor.
Line 9:
Wrapping resources in objects is the object-oriented form of [[Encapsulation (computer programming)|encapsulation]], and underlies the dispose pattern.
 
Resources are typically represented by [[Handle (computing)|handles]] (abstract references), concretely usually integers, which are used to communicate with an external system that provides the resource. For example, files are provided by the [[operating system]] (specifically the [[file system]]), which in many systems represents open files with a [[file descriptor]] (an integer representing the file).
 
These handles can be used directly, by storing the value in a variable and passing it as an argument to functions that use the resource. However, it is frequently useful to abstract from the handle itself (for example, if different operating systems represent files differently), and to store additional auxiliary data with the handle, so handles can be stored as a field in a [[Record (computer science)|record]], along with other data; if this in an [[opaque data type]], then this provides [[information hiding]] and the user is abstracted from the actual representation.