• Encapsulation is a form of data hiding.
  • Encapsulation helps to protect data from corruption.
  • Encapsulation allows for changes to the internal design of a class while the public interface remains unchanged.
  • A tightly encapsulated class does not allow direct public access to the internal data model. Instead, access is permitted only through accessor (i.e. get) and mutator (i.e. set) methods.
  • The additional time required to work through the accessor and mutator methods typically slows execution speed.
  • A tightly encapsulated class does not allow public access to any data member that can be changed in any way.so encapsulation helps to protect internal data from the possibility of corruption from external influences.
  • The mutator methods can impose contraints on the argument values. If an argument falls outside of the acceptable range, then a mutator method could throw an IllegalArgumentException.
  • The internal design of a tightly encapsulated class can change while the public interface remains unchanged.
  • An immutable class is always tightly encapsulated, but not every tightly encapsulation class is immutable.
  • Encapsulation enhances the maintainability of the code. A tightly encapsulated class allows access to data only through accessor and mutator methods.
  • A tightly encapsulated class might have mutator methods that validate data before it is loaded into the internal data model.
  • The data members of a tightly encapsulated class are declared private,so changes to the data model are less likely to impact external code.
  • Access to internal data can be provided by public accessor (i.e. get) and mutator (i.e. set) methods.
  • The mutator methods can be used to validate the data before it is loaded into the internal data model.
  • The use of accessor and mutator methods is likely to increase the size of the code and slow execution speed.
  • If a class A has a method that returns a reference to an internal, mutable object, then external code can use the reference to modify the internal state of class A. Therefore, class A can not be considered tightly encapsulated. However, the methods of a tightly encapsulated class may return a reference to an immutable object or a reference to a copy or clone of an internal object .Accessor methods are used to prevent fields from being set with invalid data.The answer would be correct if the word "Accessor" were replaced by the word "Mutator".
  • Accessor methods are used to read data members and mutator methods are used to set data members. The mutator methods can validate the parameter values before the values are used to change the state of the internal data model. The data members can not be directly manipulated by external code. The superclass is tightly encapsulated. If a class A is not tightly encapsulated, then no subclass of A is tightly encapsulated.
  • A tightly encapsulated class may have public mutator methods.The internal data model can be read and modified only through accessor and mutator methods.A class is not tightly encapsulated if the internal data model can be read and/or modified without working through accessor (i.e. get) and mutator (i.e. set) methods. If classes are tightly encapsulated, then the data members are private. A tightly encapsulated class can have public accessor and mutator methods, but it is not required to have those methods.
  • If a class is not tightly encapsulated,then no subclass of that is tightly encapsulated.If class has a public field then it is not tightly encapsulated.

 Discussion

Copyright 2016 © langobjects.com