Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

66%
+2 −0
Q&A Dealing with code maintenance when saving a large and complex entity in a single business transaction

Chain of Responsibility doesn't strike me as appropriate for this problem, at least as I understand it. You want to use CoR if you have multiple different requirements for the processing of the sam...

posted 1y ago by r~~‭

Answer
#1: Initial revision by user avatar r~~‭ · 2022-12-23T16:43:25Z (over 1 year ago)
Chain of Responsibility doesn't strike me as appropriate for this problem, at least as I understand it. You want to use CoR if you have multiple different requirements for the processing of the same data—authentication, logging, A-B testing—things we generally call concerns. What it sounds like you're going to have is a large data structure where you want to process each of the pieces of that data structure individually and then commit the entire job in a single transaction. CoR is overkill for that; just have your payload object have a field for each logical section and have a function for handling each section. You can call those functions directly or over a mediator, depending on your other requirements.

In this scenario, your biggest maintenance worry is going to be how truly isolated each section's handler is from the others. If your DTO looks like

```c#
class Section1 {
  public Group1 Group1 { get; set; }
  public Group2 Group2 { get; set; }
}
```

but your handler for `Group2` requires data from `Group1`, you'll have coupling that'll make it harder to change the processing of each group individually. Chain of Responsibility would not help with this; in fact, it would obscure what you need to do, since every middleware processor would get the entire `Section1`. The way to stay on top of this worry is:
* try to keep the groups logically isolated
* when that fails, pass inter-group data explicitly to the functions that need them

If the first bullet point is a challenge due to what the business wants from the UI, consider an intermediate stage that adapts an entire view model class into a logical model class but doesn't do anything with side effects, and then dispatches the fragments of the logical model to your handlers. This adaptation also doesn't need to be done with CoR; it's necessarily coupled to the types of your application code and must be invoked the same way with every request, which makes it a bad fit for a design pattern intended to be largely data-agnostic and dynamic.