Có hai động lực để ngăn cản truy cập cho các thành viên dữ liệu. Mục tiêu đầu tiên là để hạn chế mức độ thay đổi chương trình khi dữ liệu thay đổi thiết kế. Nếu giao diện của chức năng thành viên được (và thường nó không phải là khó khăn để giữ cho chúng khi dữ liệu thay đổi thiết kế), | file Administrator General 20English 20Learning it2002-7-6 boundary The picture also shows that when the client code needs the values of cylinder fields . for computing cylinder volume scaling printing or setting the field values the client code uses member functions getvoiume scaieCyiinder and so on rather than accessing the values of fields radius and height. This is what the dashed line means. It shows that the direct access to data is ruled out. There are two motivations for barring access to data members. The first objective is to limit the extent of changes to the program when data design changes. If the interfaces of member functions stay the same and usually it is not difficult to keep them the same when the data design changes then it is member function implementations that have to change not the client code. This is important for maintenance. The set of functions that have to change is well definedjXthey are all listed in the class definition and there is no need to inspect the rest of the program for possible implications. The second reason for barring direct client access to data members is that the client code expressed in terms of calls to member functions is easier to understand than is the code expressed in terms of detailed computations over field values provided that the responsibility is pushed to the member functions and they do the work for the client not just retrieve and set the values of the fields as is the case with the getHeight and setHeight functions . To achieve these advantages everything inside the class should be private to the class not accessible from outside the class leaving only function interfaces public accessible from the outside of the class. This would prevent the client code from creating dependencies on server class file Administrator General 20English 20Learning it2002-7-6 481 of 1187 8 17 2002 2 57 55 PM file Administrator General 20English 20Learning it2002-7-6 data. Remember that the .