Language Constructs
To make the dispose pattern less verbose, several languages have some kind of built-in support for it:
The C# language features the using
statement that automatically calls the Dispose
method on an object that implements the IDisposable
interface:
which is equal to:
Resource resource = GetResource try { // Perform actions with the resource. ... } finally { resource.Finalize; }Similarly, the Python language has a with
statement can be used to similar effect:
The Java language introduced a new syntax called try
-with-resources in Java version 7. It can be used on objects that implement the AutoCloseable interface (that defines method close):
Read more about this topic: Dispose Pattern
Famous quotes containing the words language and/or constructs:
“Different persons growing up in the same language are like different bushes trimmed and trained to take the shape of identical elephants. The anatomical details of twigs and branches will fulfill the elephantine form differently from bush to bush, but the overall outward results are alike.”
—Willard Van Orman Quine (b. 1908)
“Psychology has nothing to say about what women are really like, what they need and what they want, essentially because psychology does not know.... this failure is not limited to women; rather, the kind of psychology that has addressed itself to how people act and who they are has failed to understand in the first place why people act the way they do, and certainly failed to understand what might make them act differently.”
—Naomi Weisstein, U.S. psychologist, feminist, and author. Psychology Constructs the Female (1969)