Method Scope and Visibility


As with all type members, we can specify the scope and visibility with the familiar keywords public and private, and so on. These keywords are known as access modifiers and must be the first keyword in the method declaration. These work in the same way as with other class members as we saw in the previous chapter.

When designing your class, spend time figuring out the correct levels of visibility for all class members. In order to preserve the rules of encapsulation, data hiding, and abstraction, only those members that need to form part of the external contract should be public. Utility and helper routines used internally within a class should always have private visibility for class-level scope, or internal visibility for assembly-level scope.

The rules governing protected members are more complex and are determined by the inheritance design requirements. protected members are discussed in Chapter 7.




C# Class Design Handbook(c) Coding Effective Classes
C# Class Design Handbook: Coding Effective Classes
ISBN: 1590592573
EAN: 2147483647
Year: N/A
Pages: 90

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net