Model, business rules and resilience

I'm having trouble finding the best approach for a particular application. I'm not used to the newer architectures that replaced the old TLA (three-layer architecture), so where do I come from.

When designing the model and DAL for my application (POCO classes, right?), I had the following doubts:

  • Should Model classes show only properties and perform validation checks? A few years ago, I would implement classes that were similar to the real world, so if I had a Person who could Walk, I would create such a method. Now, every sample that I check (MVC, MVVM, etc.) has "dumb classes" that provide data and, if necessary, check this data. What about complex operations? Should they become part of the VM (I doubt it is right ...).

  • When using LINQ to SQL as an ORM resolver, should I show all attributes of the object in the model? For example, most of my objects have an identity column as their primary key. This should not concern a model or business, but simply the implementation details of my database schema.

  • If (1) and (2) are false, so the model should expose complex operations on classes, and not all entity attributes should be expanded, how can I create model classes using LINQ SQL and sqlmetal? . I have seen several examples that use partial classes to extend the functionality of schema objects, but this will expose the details of the entity (since this is just an extension).

  • If (2) is false, what is the most correct way to use sqlmetal and LINQ as an ORM? I use sqlmetal to retrieve the schema, LINQ to select objects, and then what? Create new objects based on what I have in the database?

  • In my research, I found that the VMs from MVVM and P from MVP are somewhat similar. What are the responsibilities of the speaker? And those of the ViewModel? . I focus on these two templates because they completely isolate the view from the model, an aspect that I prefer.

  • What are some methodologies for developing such applications [MVVM, MVP]? . Should I start thinking about the model, then the {P, VM} layer, then the view? This is a more subjective question, I know, but examples would be good.

I hope I was able to formulate the questions fairly objectively. I added explanations to my doubts in order to simplify the answers, but I'm afraid this made the message too big. Anyway, thanks for reading, any suggestions are very welcome.

+6
model
source share
2 answers

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.

+3
source share

In my experience, I have learned that models can become obsolete quickly, especially with increasing detail and complexity. Moreover, too much attention is paid to the development of detailed modeling artifacts, which can lead to the fact that the team will provide additional value to its customers. Therefore, I recommend that you consider a flexible approach to the release of models that provide sufficient detail for the team so that they can deliver valuable functions to your customers during an iteration of about 2-4 weeks. Take a look at Scott Ambler's Agile Model Driven Development (AMDD) methodology .

0
source share

All Articles