Maupassant came from a wealthy family, so he understood the lifestyle Matilde aspired to.
Maupassant attempted several careers before making it as a writer, but he did not come from humble beginnings. His family had money, and he lived a privileged life. His parents did not allow him to attend school without other children, and he was tutored by a priest. Maupassant therefore might have known some things about loneliness and isolation.
Natural ingenuity, instinct for what is elegant, a supple mind are their sole hierarchy, and often make of women of the people the equals of the very greatest ladies.
It seems that Maupassant also knew what it was like to be an outsider. He was kicked out of a Catholic seminary, so we can assume he did not fit in. Being from a higher class, Maupassant would have understood class distinction.