What design patterns should be applied in an application with database access

I will start developing an application that should have access to the database. Which design area usually needs to be implemented to make my application more flexible, for example, changing the database client from SQL to Oracle.

I believe that to fulfill some request I can implement a template template. And to get the connection, a single-element double check template is enough.

Is there anything else I should know before launching?

The application will be developed in C #, so there is support for object inheritance and polymorphism.

Any help is appreciated.

+6
source share
5 answers

Make sure all your code is encapsulated at the data access level. The code is against interfaces, so if you need to write a new data access library, you do not need to change the entire call code. This, at least, isolates all data access in the library. How likely is a database change? Do not make a software package for something, because it will simply complicate your life.

+8
source

Abstract something on the fly and only when you can clearly see the advantage.
Otherwise, it’s just a waste of time.

Do not think like:

I need to use the pattern [x] because it can fix [y]

Think like this:

Oh shit, had to write the same thing again. Let's see how we could avoid this ...

+6
source

Check out Martin Fowler’s Enterprise Architecture Template Catalog .

Here you can find some good ideas.

+1
source

There is a good design template for a Data Access Object , you will need to include it in C #.

Summary:

DAO implements the access mechanism necessary to work with the data source. The data source can be persistent storage, such as an RDBMS, an external service, such as a B2B exchange, a repository, such as an LDAP database, or access to a business service via CORBA Internet Inter-ORB Protocol (IIOP) or low-level sockets. A business component that uses the DAO is a simpler interface, open to the DAO for its customers. DAO completely hides the data source of customer implementation details. Because the DAO client interface does not change when the underlying data source changes implementation, this template allows the DAO to adapt to different storage schemes without affecting its clients or business components. Essentially, a DAO acts as an adapter between a component and a data source.

+1
source

you should examine the user of the data map template to preserve implementation details of how your data is stored (SQL / Oracele / Access) regardless of the use of the data itself.

http://martinfowler.com/eaaCatalog/dataMapper.html

0
source

Source: https://habr.com/ru/post/885915/