Patterns and best practices
In this section, we will have a look at two common patterns that are common to mobile applications and how to implement these usage scenarios in a platform agnostic manner.
Application preferences
Application preferences is a common scenario in mobile applications. In order to use the previously described property list on iOS and SharedPreferences
on Android, a common dictionary interface is often the most appropriate approach. The interface would then be inherited on platform-specific projects and can be injected into the common library.
For a simple demonstration, we can define a simple interface that will retrieve and save string values. The code is as follows:
public interface ISettingsProvider { string this[string key] { get; set; } }
The implementation on the Android side would use a simple dictionary using a shared preference implementation. The code is as follows:
public class SettingsProvider : ISettingsProvider { private readonly ISharedPreferences...