Data structures should expose data and have no methods
The idea that data structures should expose data and have no methods is related to the concept of separation of concerns in software design. The primary concern of a data structure is to hold and organize data, while the primary concern of methods is to perform operations on that data.
Here are a few examples of data structures that expose data and have no methods:
- Array: An array is a simple data structure that holds a collection of elements of the same type. Arrays do not have any methods and are primarily used to store and retrieve data. Here is an example of an array of integers:
int[] myArray = { 1, 2, 3, 4, 5 };
- Tuple: A tuple is a data structure that holds a collection of values of different types. Tuples do not have any methods and are primarily used to group related data together. Here is an example of a tuple that holds a name and an age:
var person = ("John", 30);
- Struct: A struct is a value...