Book contents
- Frontmatter
- Contents
- Preface
- Chapter 1 An Overview of the Visual Basic.NET Language
- Chapter 2 An Overview of Object-Oriented Programming
- Chapter 3 Structures
- Chapter 4 Classes
- Chapter 5 Access Modifiers
- Chapter 6 Abstract Classes and Interfaces
- Chapter 7 Implementing the IEnumerable and IComparable Interfaces
- Chapter 8 Designing and Implementing Exception Classes
- Chapter 9 Design Patterns and Refactoring
- Chapter 10 Object Internals: Reflection and Attributes
- Chapter 11 Object Persistence: Serialization
- Chapter 12 Building a Windows Application
- Chapter 13 Database Programming Using ADO.NET
- References
- Index
Chapter 5 - Access Modifiers
Published online by Cambridge University Press: 06 July 2010
- Frontmatter
- Contents
- Preface
- Chapter 1 An Overview of the Visual Basic.NET Language
- Chapter 2 An Overview of Object-Oriented Programming
- Chapter 3 Structures
- Chapter 4 Classes
- Chapter 5 Access Modifiers
- Chapter 6 Abstract Classes and Interfaces
- Chapter 7 Implementing the IEnumerable and IComparable Interfaces
- Chapter 8 Designing and Implementing Exception Classes
- Chapter 9 Design Patterns and Refactoring
- Chapter 10 Object Internals: Reflection and Attributes
- Chapter 11 Object Persistence: Serialization
- Chapter 12 Building a Windows Application
- Chapter 13 Database Programming Using ADO.NET
- References
- Index
Summary
One of the most confusing aspects of OOP is determining the proper access modifier to use for classes and class data members and methods. If you provide too much scope for a data member or method, you risk violating data encapsulation, leading to unwanted data access. If your scope is too restrictive, other classes that need access to a class's data or methods won't be able to access them. In this chapter we discuss the different access modifiers, how they are used to manage class member and method scoping, and when to use each modifier. At the end of the chapter we discuss how these access modifiers work with classes themselves.
The access modifiers available in VB.NET are the following:
Public
Private
Protected
Friend
Protected Friend
We also discuss the modifier Shadows in this chapter. A method declared as Shadows in a derived class hides any methods in the base class with the same name. In effect, a method that shadows another method redefines the shadowed method's behavior.
PUBLIC ACCESS
A class member or method marked as Public can be accessed by any part of the class body, by any part of the project in which the class definition is located, or from an assembly built from the project containing the class definition. This is the least restrictive access and is frequently misused by many programmers.
- Type
- Chapter
- Information
- Object-Oriented Programming with Visual Basic.NET , pp. 136 - 157Publisher: Cambridge University PressPrint publication year: 2004