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:
“Our goal as a parent is to give life to our childrens learningto instruct, to teach, to help them develop self-disciplinean ordering of the self from the inside, not imposition from the outside. Any technique that does not give life to a childs learning and leave a childs dignity intact cannot be called disciplineit is punishment, no matter what language it is clothed in.”
—Barbara Coloroso (20th century)
“In some extremely important ways, people are what you expect them to be, or at least they behave as you expect them to behave.”
—Naomi Weisstein, U.S. psychologist, feminist, and author. Psychology Constructs the Female (1969)