6.1 data abstraction
Hiding is not just as simple as placing a function layer between variables. The class does not simply use getter and setter to push variables out, but exposes abstract interfaces so that users can operate on the Data ontology without understanding the data implementation.
As shown in the following figure, a reader needs to obtain the current reading progress. The interface is defined as follows:
Public interface paperreader
{
Double gettotalpages ();
Double getcurrentpageindex ();
}
The better way is:
Public interface paperreader
{
Double getcurrentprogress ();
}
Adding Values and assigning values is strictly required.
6.2 anti-symmetry of data and objects
Procedural Code (code using the data structure) allows you to add new functions without modifying the existing data structure. Object-oriented Code allows you to add new classes without modifying existing functions.
6.3 The Law of Demeter Class C method F should only call the method of the following object :. class C. object created by F. the object passed to F as a parameter. objects held by object variables of class C. 6.4 data transmission objects (DTO, data transfer objects) have only public variables and have no function classes, which are called DTO.