The function of allegory in literature is to convey a complex idea through an in-depth metaphorical narrative. Famous allegories include Dante's Divine Comedy, George Orwell's Animal Farm, and John Bunyan's The Pilgrim's Progress. All of these works use allegorical techniques to convey different messages to the ones literally written on the page. An allegory can be thought of as an extended metaphor.
Literary techniques are often used by fiction or poetry writers in order to convey an idea in a more enjoyable or easily comprehensible fashion. Simile, metaphor, and prophetic fallacy are three such methods. A simile uses the word "like" or "as" to relate the action or object being described to something more familiar. A metaphor is very similar, except that it doesn't use a signifying word such as "like;" it merely describes something as if it were something else. For example, an angry person could be described as having "boiling blood," but his or her blood isn't literally boiling.
An allegory in literature is essentially an extended metaphor. The main difference is that allegories usually take the form of entire plot lines, rather than just a description or a passage. In Animal Farm, Orwell describes a revolution amongst animals on a farm to actually make a point about capitalist democracy in England and the United States and the Communist regime in Russia. Orwell did this to put the political content of his book into a more easily-to-digest package, yet still make a political point.
Any story which is an allegory in literature can also be interpreted at face value. This means that Animal Farm could literally be interpreted as a story about animals. The main function of an allegory in literature is to mask an idea through a clever series of symbolic meanings, so that in context of the extended metaphor, the idea can be understood more deeply. Stories or poems which are allegorical can be thought to have two levels, one literal and one figurative.
A famous allegory in literature is Dante's Divine Comedy, in which Dante himself journeys through hell, purgatory, and heaven, guided through the first by another poet, Virgil. Throughout the stories, Dante is really tracing his religious life, taking himself from the "dark wood," which is generally thought to represent a place in which he has no religion, to paradise, which is spiritual enlightenment and ultimately, Christianity. Although this could have been described literally, in terms of an autobiography, Dante's version is more encapsulating because it employs mythical scenes and a larger-than-life story.