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:
“When youre lying awake with a dismal headache, and repose is
tabood by anxiety,
I conceive you may use any language you choose to indulge in without impropriety;”
—Sir William Schwenck Gilbert (18361911)
“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)