Skip to content

Commit cf08836

Browse files
committed
Extend motivation and use cases section
1 parent 3cecdd9 commit cf08836

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

proposals/protected_attribute.txt

+14-4
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,20 @@ instance. While in the setter routine the copying serves robustness by
2828
"disentangling" the data stored in the derived type from the original data, the
2929
getter routine and the connected copy operation might be superfluous, when the
3030
consumer only wants to read but not modify the data stored in the derived type
31-
intance. By allowing for a direct read-only access, one could enhance
32-
efficiency in those case without sacrificing the robustness of data
33-
encapsulation and hiding.
31+
intance.
32+
33+
By allowing for a direct read-only access, one could enhance efficiency in those
34+
cases without sacrificing the consistency of the encapsulated data. Direct
35+
access is possible with current Fortran already, but only if the respective
36+
derived type component is public. This would jeopardize data consistency,
37+
though, as a consumer could change the respective component arbitrarily, without
38+
using the provided setter routine.
3439

3540
This proposal suggests to allow the "protected" attribute already used for
3641
module variables being used for derived type components as well. It would also
3742
remedy the asymmetry between the attributes "private"/"public" and the attribute
3843
"protected", as the former two can be applied to both, module variables and
39-
derived type components, while the latter only for module variables.
44+
derived type components, while the latter only for module variables so far.
4045

4146

4247
3. Use Cases
@@ -86,4 +91,9 @@ operation:
8691
! Dummy argument of the called routine must be intent(in)
8792
call some_routine_processing_but_not_changing_the_array(storage%array)
8893

94+
! Inconsistent change, consumer is supposed to call set() to change
95+
! encapsulated data.
96+
! Uncommenting the next line should trigger a compiler error.
97+
!storage%array(1) = -1
98+
8999
end program use_data

0 commit comments

Comments
 (0)