tailieunhanh - Praise for C# 2.0: Practical Guide for Programmers 2005 phần 2
Tham khảo tài liệu 'praise for c# : practical guide for programmers 2005 phần 2', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Access Modifiers 13 visible within the class itself. The visibility of its protected methods and data fields is restricted to the class itself and to its subclasses. Internal methods and data fields are only visible among classes that are part of the same compiled unit. And finally methods or data fields that are protected internal have the combined visibility of internal and protected members. By default if no modifier is specified for a method or data field then accessibility is private. On the other hand if a class is internal the semantics of the access modifiers is identical to those of a public class except for one key restriction Access is limited to those classes within the same compiled unit. Otherwise no method or data field of an internal class is directly accessible among classes that are compiled separately. When used in conjunction with the data fields and methods of a class access modifiers dually support the notions of information hiding and encapsulation. By making data fields private data contained in an object is hidden from other objects in the system. Hence data integrity is preserved. Furthermore by making methods public access and modification to data is controlled via the methods of the class. Hence no direct external access by other objects ensures that data behavior is also preserved. As a rule of thumb good class design declares data fields as private and methods as public. It is also suggested that methods to retrieve data members called getters and methods to change data members called setters be public and protected respectively. Making a setter method public has the same effect as making the data field public which violates the notion of information hiding. This violation however is unavoidable for components which by definition are objects that must be capable of updating their data fields at runtime. For example a user may need to update the lastName of an Id object to reflect a change in marital status. Sometimes developers .
đang nạp các trang xem trước