Skip to main content
deleted 8 characters in body
Source Link
user453443
user453443

Leading question is: what methods need to be available for the encapsulated fields support?

When using collections the practical solution is the second one:

OR should I just add getters for the three objects and let the rest of my program use that to manipulate them.

...since there is a considerable number of methods the collections support (e.g. contains, iterator, size) that most probably get used by the caller code. Even when there are methods that should be unavailable for the encapsulated Collection fields the second solution is the practical one with a slight change of the getters returning unmodifiable collections returned by java.util.Collections's methods prefixed with unmodifiable.

For a different type of fields (different from Collection type) and with the requirement of refining the visible methods of the encapsulated fields wrapper methods most probably are preferred, depending on the use cases.

Leading question is: what methods need to be available for the encapsulated fields support?

When using collections the practical solution is the second one:

OR should I just add getters for the three objects and let the rest of my program use that to manipulate them.

...since there is a considerable number of methods the collections support (e.g. contains, iterator, size) that most probably get used by the caller code. Even when there are methods that should be unavailable for the encapsulated Collection fields the second solution is the practical one with a slight change of the getters returning unmodifiable collections returned by java.util.Collections's methods prefixed with unmodifiable.

For a different type of fields (different from Collection type) and with the requirement of refining the visible methods of the encapsulated fields wrapper methods most probably are preferred, depending on the use cases.

Leading question is: what methods need to be available for the encapsulated fields?

When using collections the practical solution is the second one:

OR should I just add getters for the three objects and let the rest of my program use that to manipulate them.

...since there is a considerable number of methods the collections support (e.g. contains, iterator, size) that most probably get used by the caller code. Even when there are methods that should be unavailable for the encapsulated Collection fields the second solution is the practical one with a slight change of the getters returning unmodifiable collections returned by java.util.Collections's methods prefixed with unmodifiable.

For a different type of fields (different from Collection type) and with the requirement of refining the visible methods of the encapsulated fields wrapper methods most probably are preferred, depending on the use cases.

Source Link
user453443
user453443

Leading question is: what methods need to be available for the encapsulated fields support?

When using collections the practical solution is the second one:

OR should I just add getters for the three objects and let the rest of my program use that to manipulate them.

...since there is a considerable number of methods the collections support (e.g. contains, iterator, size) that most probably get used by the caller code. Even when there are methods that should be unavailable for the encapsulated Collection fields the second solution is the practical one with a slight change of the getters returning unmodifiable collections returned by java.util.Collections's methods prefixed with unmodifiable.

For a different type of fields (different from Collection type) and with the requirement of refining the visible methods of the encapsulated fields wrapper methods most probably are preferred, depending on the use cases.