Pattern: Facade
Facade is is an object that provides a simplified interface to a larger body of code, such as a class library.
Purpose of .NET implementation
You are the creator of EFCore that provides ORM capabilities to the developers.
You want also to have a simplified interface to interact with the underlying database and provide simple methods like EnsureCreated(), BeginTransaction(), etc.
The Facade pattern provides a unified interface to a set of interfaces in a subsystem. It defines a higher-level interface that makes the subsystem easier to use by providing a single entry point for common operations.
Example in .NET :
Facade
Facade example for Pattern Facade
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
namespace Facade;
internal class FacadeDemo
{
public static void ExecuteSql()
{
MyDbContext cnt = new();
DatabaseFacade dbFacade = cnt.Database;
//calling the facade for create the database
dbFacade.EnsureCreated();
//calling the facade for begin a transaction
dbFacade.BeginTransaction();
}
}
public class MyDbContext:DbContext
{
}
See Source Code for Microsoft implementation of Facade
SourceCode DatabaseFacadeLearn More
C2Wikidofactory
DPH
Wikipedia
Homework
Implement a Facade that will allow you to display a question in a MessageBox with a single method call in a console application and return yes/no as a result.