What functionality is built into business objects?

What functionality, in your opinion, should be built into a sustainable business object with a minimum minimum?

For instance:

  • check
  • way to compare with another object of the same type
  • the ability to cancel (the ability to roll back changes)
+4
source share
4 answers

Functionality dictated by domain and business.

Read the Domain Managed Project .

+2
source

A permanent business object should consist of the following:

  • Data
  • New
  • Save
  • Delete
  • Serialization
  • Deserialization

Often you distract functionality to get them into a repository that supports:

  • Getbyd
  • Getall
  • GetByXYZCriteria

You can also wrap this type of functionality in collection classes (e.g. BusinessObjectTypeCollection), however there are many moves to use the repository template in Driven Design to provide these types of accessories (e.g. InvoicingRepository.GetAllCustomers, InvoicingRepository.GetAllInvoices).

You can put business rules in New, Save, Update, Delete ... but sometimes you may have an external business rule mechanism with which you pass objects.

+1
source

This is just one part of the answer, but I would say that you need a way to get to all the objects with which this object has a relationship. At first, you can try to be smart and include only one-way navigation for some relationships, but I found that this is usually more of a problem than it's worth.

All persistent frameworks also include crawlers, ways to perform cascading deletions ... sorts ....

Once you begin modeling, all business objects should know how to manage themselves. Whenever you find another class too large, referring to your business object, it is usually time to push this behavior to the business object itself.

0
source

Of the three things noted in the question, I would say that validation is the only one that is really needed. Others depend on the general archeometry of the application.

In addition, business rules must be in business objects.

The question of whether an object should perform its serialization is an interesting question. In the past, I had great success, since each object processed its own serialization, but I also see that it deserves to load the serialization module and save business objects in the same way as the GUI writes and reads from objects. Then your check will protect against errors in the database or files.

I cannot think of anything else that is required at all.

0
source

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


All Articles