FACADE provides a consistent interface for a set of interfaces of the subsystem, such as access to the database, when switching from one data to another, the interface is unchanged, so the client does not change, and the coupling is reduced.
Related:
#include
// mfc dao database classes.
Class DB
{
Static Cdaodatabase S_DB;
PUBLIC:
Static void init ()
{
Try
{
s_db.open (_t ("*. MDB"), False, False, "; PWD = 1");
} catch (cdaoException * e)
{
AfxMessageBox (E-> M_PerrorInfo-> m_StrDescription);
Return;
}
}
Void Store (int IID, int icount)
{
Try
{
s_db.excute (buildinsertionStatement (IID, ICOUNT));
} catch (cdaoException * e)
{
AfxMessageBox (E-> M_PerrorInfo-> m_StrDescription);
Return;
}
}
Private:
CSTRING BuildInsrtionStatement (int IID, int icount)
{
CString Str;
Str.Format ("INSERT Inter Products Value ('% d', '% d'), pd.id, pd.count");
Return Str;
}
}
// Client
void main ()
{
Db.init ();
DB.Store (1,5);
}
Note: The above is an example of inserting an Access database. When the database is SQL Server, change the function and variable related to the S_DB and init () in the DB without changing the code in the client. Reduce the coupling.