Skip to content

Instantly share code, notes, and snippets.

Created Jul 7, 2019
What would you like to do?
// Interface
public interface IDatabase
void Save(int orderId);
public interface ILogger
void LogInfo(string info);
public interface IEmailSender
void SendEmail(int userId);
// Các Module implement các Interface
public class Logger : ILogger
public void LogInfo(string info) {}
public class Database : IDatabase
public void Save(int orderId) {}
public class EmailSender : IEmailSender
public void SendEmail(int userId) {}
// Hàm checkout mới sẽ như sau
public void Checkout(int orderId, int userId)
// Nếu muốn thay đổi database, logger ta chỉ cần thay dòng code dưới
// Các Module XMLDatabase, SQLDatabase phải implement IDatabase
//IDatabase db = new XMLDatabase();
//IDatebase db = new SQLDatabase();
IDatabase db = new Database();
ILogger log = new Logger();
log.LogInfo("Order has been checkout");
IEmailSender es = new EmailSender();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment