The friendship between the two main characters is born out of circumstance - they have simply been thrown together. But Alan is immediately grateful to David for telling him about the plot to kill him.
Following this start, each shows himself to be a good friend to the other. Their loyalty is tested several times by the events that occur in the story as they travel across Scotland.
One of the most severe tests is when they are being chased across Rannoch Moor. David is suffering from stress and exhaustion and finds fault with Alan. Alan is less worn down by the chase and impatient with David's principles. They fall out about everything and are increasingly unable to find a way to be reconciled. This comes to a head with David challenging Alan to fight and Alan realising that David is ill.
Another more positive test is when David has to go to see Rankeillor to denounce his uncle and claim his inheritance. Alan has to stay hidden and to trust David with his life, since if David makes a false move then it could result in Alan being captured and killed. Alan gives David his complete trust and it is repaid by the outcome.
But there is also constant tension between them because they come from very different cultural and political backgrounds. Part of this focuses on their different ideas of honour and respect.
Alan believes respect is due to him as one who ‘bears a king's name’. Yet he is scathing about David calling himself ‘David Balfour of Shaws’. His idea of a gentleman and of honour is about more than having a title or fine manners.
As a Highlander, Alan is part of the clan system, and the ownership of land and property are regarded as less important than loyalty to the clan chief. Many clan members and chiefs, like Cluny, have also lost their lands and have to maintain their sense of honour by other means.
While name and title are part of this, it is just as important that a gentleman should know how to behave. This idea of honour comes across strongly in the incident in Cluny’s cave, when Alan loses his money at cards and then borrows from David to cover his debts.
When he realises that the money belongs to David, Cluny insists on returning it to him and pretends that the play was just for fun. Alan is left feeling mortified by this. As a gentleman he wants to be able pay his debts and not lose face.
Alan demands respect and will fight the man who does not give it to him. David has a strong sense of honour which is based on his personal integrity. This is what motivates his actions, which are often not easy to carry out.
Therefore as the two characters illustrate, there are different ideas of what honour and respect should involve.