Here are some thoughts for you about model design from my experience.
- Relax. No matter what you do in your model design, it can still be open to criticism and complaints from people. You cannot please everyone. If you make it a completely buzzword that matches the latest thinking of things, it can be complex, abstract, or hard to understand. On the other hand, if you just pat him together without much rhyme or reason, you too can get into trouble. The code is used for the application, it should make the application fall into the completed basket in such a way that it is easy to read, easy to understand, easy to maintain. Many other considerations are secondary.
- What is the level of exposure . The correct answer depends on what the future of your application will be, and any approach can be a good solution. Something that helps me decide what to do with the models is to pretend that I am writing more than one level of the consumer / user / user interface that sits on top of the models. Thus, usually an application has only one user interface. But pretend that the application will have more than one ui - say, both the web interface and the actual smartphone GUI interface. Pretending to be both will help you make the decision to include logic in the level of access to models / data and less and less logic at the user interface level. If you make your models very thin and expose ORM aspects for the user interface, you will be tempted to put good ORM code in the UI. This can lead to more schizophrenic code. This makes it so that if you ever decide to change the backends, say from SQL to another flavor of SQL, or Cassandra, or to something else, you pretty much can't.
- Consider using a web service to access data. You can put all your data access into a web service. Then your user interface layer will use the web service to access the data, both for reading and writing. It sounds a bit radical, but it has a number of key benefits.
- This helps to separate the problems of the user interface level and the business logic level.
- It allows you to add additional types of user interface later with relatively little effort. You can create tools on your platform (if they do not already exist), which makes it very simple, and you may find that your code is getting smaller.
- This makes it easier to completely change how your backend works without changing any of your user interface code.
I moved the application from SQL to Cassandra this way. Separating all the data access in the web service, introducing a good set of tests for the web service, and then redeploying the web service. After that, the application became much smaller and cleaner.
I think you're worried about the wrong things. Think of the data access layer / models as providing ideal services that will make your user interface as easy to implement as possible. Imagine what this ideal level of access to data will look like, which will facilitate the work. Align this interface and then animate it. How it looks inside is less important.
It is important that the application must be completed, it must work, and must be easy to read and easy to maintain. Personally, I would not sweat everything else. If the key requirement of your application is that it impresses someone when it looks from the inside out, you are worried about the wrong things. Read what other people have to say and use that resonates within you and makes sense, but donβt sweat if what you read does not seem useful to your projects.
Unoti
source share