public static void Run() { // In this example, we abstract the methods save and retreive // inside the Repository interface. Define SQL and SharePoint classes // and implement the concrete methods to implement the respective behavior. // This achieves Inheritance // SQL way IRepositoryConnection connection = new SQLRepositoryConnection(); IRepository repository = new SQLRepository(connection); // private retrieve method is encapsulated and hidden from the public // this achieves Encapsulation AppData data = repository.Retrieve(1); // modify the data... and call save repository.Save(data); // SharePoint way connection = new SharePointRepositoryConnection(); repository = new SharePointRepository(connection); data = repository.Retrieve(1); repository.Save(data); }
public static void DemoRun() { // We have defined an interface IRepository // And we implement 2 classes SQL and SharePoint // which does serve the common purpose to Save and Retrieve the recods. // Observe, with this design, we are making the classes // to be extendible but not modifiable. // These classes can be further extended to add more features // but need not have to be modified. // SQL way IRepositoryConnection connection = new SQLRepositoryConnection(); IRepository repository = new SQLRepository(connection); AppData data = repository.Retrieve(1); repository.Save(data); // SharePoint way connection = new SharePointRepositoryConnection(); repository = new SharePointRepository(connection); data = repository.Retrieve(1); repository.Save(data); }