Programming tips

I know this is a busy question and there can be many, many answers, but ..... I am creating a small application that will be used by me and several other friends at the moment, and if he likes it more, I will distribute it to them. This is a simple customer tracking app for people with disabilities. It will track customers, payments, payment history, schedule, files (photos, emails, etc.). And, perhaps, a little more, but overall a very simple program. Oh yes, using SQLExpress as the source. My question is this: what is the best approach to designing the objects needed for this application? I read articles about data access layers and business objects, but I never created them from scratch. I thought about such objects as โ€œClientโ€, โ€œPaymentโ€, etc., And, of course, all the properties that come with them, but when it comes to changing the database, you should add methods to add, update, delete and etc. be in DAL with an object just passing the name of the stored procedure?

I know that there is a lot of information that is probably missing, but hopefully you can get a gist (sp?) Of what I'm trying to do.

** to reply to some of the messages:

I agree that the object will be split into dal, but I will need to learn more about how to create it this way ... again, new to OO programming, so I cannot fully see the whole picture.

Here's the DAL that a friend made and allowed me to use it:

namespace DataAccess{ public class SQLDataBase { public SQLDataBase(); public SQLDataBase(string EncodedConnectionString); public SQLDataBase(string EncodedConnectionString, int ConnectionTimeout); public string ConnectionString { get; set; } public int ConnectionTimeout { get; set; } public string EncodedConnectionString { get; } public void RunSpGetScaler(string spName, SqlParameter[] parms, ref DateTime ReturnValue); public void RunSpGetScaler(string spName, SqlParameter[] parms, ref decimal ReturnValue); public void RunSpGetScaler(string spName, SqlParameter[] parms, ref int ReturnValue); public void RunSpGetScaler(string spName, SqlParameter[] parms, ref string ReturnValue); public DataSet RunSpReturnDS(string DatasetName, string spName); public DataSet RunSpReturnDS(string DatasetName, string spName, SqlParameter[] parms); public int RunSpReturnRecordCount(string spName); public int RunSpReturnRecordCount(string spName, SqlParameter[] parms); public string RunSpReturnString(string spName, SqlParameter[] parms, string returnParm); public SqlConnection RunSqlConnection(); } 

}

pretty simple ... the only problem I am facing is when I create any objects to use it, I have to write methods for every call I make in the database .... like this:

  //Declarations - which I don't thinkk should be in the object itself private DataAccess.SQLDataBase oDatabase = null; private string sEncodedConnectionString = app.Default.EncodedDBString; private int iConnectionTimeout = 15; public DataSet GetClientInformation(int iClinetID, string sClientName) { oDatabase = new SQLDataBase( sEncodedConnectionString, iConnectionTimeout); string spName = "GetClientInformation"; string dsName = "GetClientInformation"; try { SqlParameter[] Params = new SqlParameter[2]; Params[0] = new SqlParameter("@ClientID", iClientID); Params[1] = new SqlParameter("@ClientName", sClientName); DataSet ds = oDatabase.RunSpReturnDS(dsName, spName, Params); return ds; } catch (Exception e) { throw (e); } } 

So, for my client object, I have this and several other methods for adding, modifying, or selecting data for the โ€œclientโ€. Logically, this does not make sense to me, because it seems that I can not use it without having to have several other dependencies with it.

+4
source share
2 answers

Creating separate layers allows your application to share problems. UIs (and other hosts) gain access to an object-oriented model that is easily consumed without knowing anything about how data is stored. In templates such as MVC, you can even have a controller layer that mediates between views and the model. Another very good sample to study.

The object model uses a data access layer and does not have direct knowledge of how data is stored and retrieved. The level of data access may be slightly flatter and more focused on the ability to effectively access and record data. The public object model layer should be a good object-oriented layer that can potentially be maintained compatible.

Other reasons for layers:

  • Minimize the outflow of changes: you can swap how you store, affecting as few layers, subsystems, and code as possible.
  • Testing. You can make fun of full layers on unit test high layers.
  • Implementation of the denouement: you can start with a simple layer (e.g. files, etc.) while you expect another (or future development) for this other level.
+3
source

I would start by reading and understanding N-tier architecture. This should help you understand the need for logical separation and abstraction. From there, if you use SQL Server and .NET, learn the Microsoft Entity Framework as your level of data access. It is easy to start and quite powerful.

+3
source

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


All Articles