Attributes can
be tagged as public or private. Ideally,
attributes are private to the object as part of its internal affairs.
Do not expose them as part of the interface of the object because
attributes are an implementation issue and must not be part of the
external contract of the object. In this way, the implementation can
be modified to follow changing requirements without having any external
impact. However, sometimes to satisfy efficiency constraints, attributes
can be made public so that peer objects can access them directly.
There
is no difference in the way public or private attributes are generated
in C. Attributes are simply data members inside an object structure,
and as such are always public.
However, when
you assign public or private access
to an attribute, the visibility applies to the accessor and mutator
operations for the attribute, not to the attribute itself:
- Assigning public access to an attribute causes
the Code Generator to generate public accessor and mutator operations
for it.
- Assigning private access causes the
code generator
to generate static accessor and mutator operations for it.