A
Adrian Hawryluk
William said:I was thinking of the case where the modification was to something
that used A, but the modification needed information from C.
E.g. a piece of state in C is needed
by somthing using A, but the need for this piece of state
was not anticipated. If there is no encapsulation I can write
something like
needed_state = a_pointer->b_pointer->c_pointer->low_level_state
With encapsulation I need to write something like
needed_state = a_pointer_get_needed_state(a_pointer)
which needs
needed_state = b_pointer_get_needed_state(b_pointer)
which needs
needed_state = c_pointer_get_needed_state(c_pointer)
and I have to modify a bunch of files.
It may be more of a hassle, but I still think that it is cleaner to
modify the files since, the system may change and the state is no longer
in C but in D. In which case, your 'needed_state =
a_pointer->b_pointer->c_pointer->low_level_state' either will not
compile or will work incorrectly (the worse of the two) and then you
have a bug that may not be trivial to track down.
I'm a bit proponent of encapsulation. It keeps things neat and tidy
(for the most part) and keeps others hands out of the cookie jar, where
they might find an unexpected bug biting at their fingers (unexpected
consequences). Also, if a bug is found in the encapsulated code, you
fix it in one place instead of all over the system (been there, done
that, don't want to go there again).
For all but the simplest of structs would I consider exposing it, and
even then, I would have to think about it at length to make sure it is
something that will not change over the course of development.
Adrian
--
==========================================================
Adrian Hawryluk BSc. Computer Science
----------------------------------------------------------
Specialising in: OOD Methodologies in UML
OOP Methodologies in C, C++ and more
RT Embedded Programming
__--------------------------------------------------__
----- [blog: http://adrians-musings.blogspot.com/] -----
'--------------------------------------------------------'
My newsgroup writings are licensed under the Creative
Commons Attribution-Noncommercial-Share Alike 3.0 License
http://creativecommons.org/licenses/by-nc-sa/3.0/
==========================================================