This is a compromise.
Using value structures can be a beautifully simple way to group a collection of data. They can be very stupid if you start to resort to many auxiliary routines and rely on them for other purposes. Be strict with yourself about when and how to use them, and they are fine. Zero methods on these objects are a good way to make this obvious to you.
You may have several classes that you use to solve the problem, I will call it a module. The presence of structural elements in the module is easy to argue. Outside the module, you should hope for good behavior. You do not have strict interfaces, so you should hope that the compiler will warn you about misuse.
Given this statement, I think they are more suitable for anonymous or verbose namespaces. If they fall into public interfaces, people tend to add sugar to them. Remove sugar or reformat it into a first-class object with an interface.
I think they are more suitable as const objects. The problem that you encounter is that you (try) to maintain the immutability of this “object” everywhere that it has been used throughout its entire life cycle. If another level of abstraction wants them with slight mutations, make a copy. The named parameter idiom is good for this.
Domain Driven Design provides thoughtful and thorough processing on this subject. It characterizes his more practical understanding of how to understand and facilitate design.
The clean code also discusses the topic, albeit from a different perspective. This is more morality .
Both are awesome books and are usually recommended outside of this topic.
source share