JSF.UNENCAPSULATED.GLOBAL

Unencapsulated global data will be avoided.

Rationale

Global data is dangerous since no access protection is provided with respect to the data.

Note: If multiple clients require access to a single resource, that resource should be wrapped in a class that manages access to that resource. For example, semantic controls that prohibit unrestricted access may be provided (e.g. singletons and input streams).

Example 1

Copy
  int32 x=0; // Bad: Unencapsulated global object.
  
  class Y {
      in32 x;
  public:
      Y(int32 y_);
      int32 get_x();
      void set_x();
  };
 
 Y y (0); // Bad: Unencapsulated global object.

Unencapsulated global data can be dangerous and thus should be avoided. Note that objects with only get and set methods, or get and set methods for each attribute are not considered to be encapsulated.