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:
“Whether we regard the Womens Liberation movement as a serious threat, a passing convulsion, or a fashionable idiocy, it is a movement that mounts an attack on practically everything that women value today and introduces the language and sentiments of political confrontation into the area of personal relationships.”
—Arianna Stassinopoulos (b. 1950)
“To me the female principle is, or at least historically has been, basically anarchic. It values order without constraint, rule by custom not by force. It has been the male who enforces order, who constructs power structures, who makes, enforces, and breaks laws.”
—Ursula K. Le Guin (b. 1929)