Oscar Wilde was the pet of the fashionable London set through his journey towards fame and at the height of his career. As a result, he would take the traits that he most commonly saw among his society and would infuse them into the building of his characters.
The dandy is not a literary creation. There were a number of well-to-do bachelors in London than, rather than taking the expected route of marrying and working in Parliament, or at the foreign office, would instead live off their family fortunes, above their means, and always keeping fashion as their focal point. They were Victorian versions of the modern-day heirs whom we see on TV doing reality shows for lack of an occupation, and always making sure that they look good.
Algernon: If I am occasionally a little over-dressed, I make up for it by being always immensely over-educated.
A lover of money, youth, and beauty, Wilde is then the unrivaled creator of the most famous dandies in fictional literature: Algernon Moncrieff from The Importance of Being Earnest, Lord Goring from An Ideal Husband, and Lord Darlington from Lady Windermere's Fan.
These three dandies bare a lot of similarities. First, they are all single, have no occupations, seem to be (like Wilde, himself) pets of the higher classes, and their clever speech welcomes them everywhere. As mouthpieces of Oscar Wilde, they are the conduits through which Wilde expresses his most famous maxims. Hence, the use of the dandies is to show the lighter side of an otherwise snobbish, thick, and classicist society where money and name rules it all.
Most of the comedic value of the dandies lays in their tendency to insult people and to always be "hard up", or broke. All three, at some point say something about the latter.
Algernon: I wish you would offer one [reward]. I am more than usually hard up.
Lord Darlington:Ah, nowadays we are all of us so hard up, that the only pleasant things to pay arecompliments. They’re the only things we can pay.
Similarly, they "abuse their relations" and seem quite anoyed at their presence. Case in point, Algernon's annoyance at the duties tasked for him by his aunt, Lady Bracknell. Similarly, Lord Goring seems to have a jaded relationship with his father, Lord Caversham, who consistently reminds Goring how worthless he really is. For this reason, Goring uses his witty talk with Caversham which confuses and aggravates the latter. Just like Algernon says that relatives are people who don't know how to live nor when to die, Lord Goring equally remarks how his father seems to always appear when he is least wanted around.
In all, the dandies are refreshing and insightful to the storyline. They are Wilde's witty talkers because they express the viewpoints of the author. They provide a handsome, funny, and witty comic relief to the play and they also leave the audience with the most memorable moments, as their words become the staple of what a Wilde play is actually like.